Search query interactions on online social networks

ABSTRACT

In one embodiment, a method includes accessing a social graph that includes a plurality of nodes and edges, receiving from a user a structured query comprising references to selected nodes and selected edges, generating a query command based on the structured query based on the structured query comprising a first query constraint and a second query constraint, identifying a first set of nodes matching the first query constraint and at least in part matching the second query constraint, identifying a second set of nodes matching the second query constraint, and generating search results based on the first and second set of nodes.

TECHNICAL FIELD

This disclosure generally relates to social graphs and performingsearches for objects within a social-networking environment.

BACKGROUND

A social-networking system, which may include a social-networkingwebsite, may enable its users (such as persons or organizations) tointeract with it and with each other through it. The social-networkingsystem may, with input from a user, create and store in thesocial-networking system a user profile associated with the user. Theuser profile may include demographic information, communication-channelinformation, and information on personal interests of the user. Thesocial-networking system may also, with input from a user, create andstore a record of relationships of the user with other users of thesocial-networking system, as well as provide services (e.g. wall posts,photo-sharing, event organization, messaging, games, or advertisements)to facilitate social interaction between or among users.

The social-networking system may send over one or more networks contentor messages related to its services to a mobile or other computingdevice of a user. A user may also install software applications on amobile or other computing device of the user for accessing a userprofile of the user and other data within the social-networking system.The social-networking system may generate a personalized set of contentobjects to display to a user, such as a newsfeed of aggregated storiesof other users connected to the user.

Social-graph analysis views social relationships in terms of networktheory consisting of nodes and edges. Nodes represent the individualactors within the networks, and edges represent the relationshipsbetween the actors. The resulting graph-based structures are often verycomplex. There can be many types of nodes and many types of edges forconnecting nodes. In its simplest form, a social graph is a map of allof the relevant edges between all the nodes being studied.

SUMMARY OF PARTICULAR EMBODIMENTS

In particular embodiments, a user of a social-networking system maysearch for objects associated with the system using a structured queriesthat include references to particular social-graph elements. Structuredqueries may provide a powerful way for users of an online social networkto search for objects represented in a social graph based on theirsocial-graph attributes and their relation to various social-graphelements.

In particular embodiments, in response to a structured query having bothan inner constraint and an outer constraint, such as a nested searchquery, the social-networking system may identify objects associated withthe online social network that satisfy both the inner and outerconstraints. The process of searching verticals of objects associatedwith the social-networking system may be improved by using queryhinting, where the outer query constraint is used when identifyingobjects that match the inner query constraint. For example, a relativelycomplex structured query, such as “Photos of females taken in PaloAlto”, could be parsed so that a user vertical is searched to identifyusers who are female, and by using an operator that allows arguments tobe absents from some results, such as a “weak and” (WAND) operator, toidentify at least some female user who also are tagged in photos in PaloAlto. Next, a photos vertical could be searched to identify photos takenin Palo Alto where any of the identified female users are tagged. Inparticular embodiments, the results from the first vertical could bescored and ranked, and those scores could be used when scoring theresults of the second vertical. In this way, the search of the verticalcorresponding to objects requested by the outer constraint is morelikely to generate results that satisfy the search query. This may alsoallow the social-networking system to produce better search results andmay improve the processing efficiency for generating these results.

In particular embodiments, the social-networking system may parsestructured search queries and generate query commands that includeinverse operators. The process of searching verticals of objectsassociated with the social-networking system may be improved by usinginverse operators, where one of the query constraints may be modified toinclude its inverse constraint. When parsing a structured query havingboth an inner query constraint and an outer query constraint, such as anested search query, the typical processing of the query may produce aninadequate number of search results. This may happen, for example,because the inner query constraint produces too many results, reducingthe likelihood that any of them will intersect the outer query. Theprocess of searching verticals of objects associated with thesocial-networking system may be improved by using an inverse operator,where the inverse constraint is used instead of the original queryconstraint when searching the vertical for matching objects. Forexample, a relatively complex structured query, such as “Photos of meliked by people in China”, could be parsed so that instead of using a“liked_by” operator to search for photos liked by users in China, toinstead user a “likers_of” operator to search for users of photos of thequerying user. In this way, an inverse operator may be used so that thesearch of a particular vertical produces better search results, and mayimprove the processing efficiency for generating these results.

In particular embodiments, the social-networking system may rank searchresults based on the search intent of the querying user. Users may havedifferent intents when running different search queries. The searchalgorithm used to generate search results may be modified based on thesesearch intents, such that the way search results are ranked in responseto one query may be different from the way search results are ranked inresponse to another query. The social-networking system may identify oneor more search intents for the search query, and then rank the searchresults matching the search query based on the search intents. Searchintent may be determined in a variety of ways, such as, for example,based on social-graph elements referenced in the search query, termswithin the search query, user information associate with the queryinguser, search history of the querying user, pattern detection, othersuitable information related to the query or the user, or anycombination thereof. For example, a particular social-graph elementreferenced in a search query may correspond to a particular searchintent. By using search intent when ranking search results, thesocial-networking system may be able to more effectively present searchresult are more relevant or of more interest to the querying user.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example network environment associated with asocial-networking system.

FIG. 2 illustrates an example social graph.

FIG. 3 illustrates an example partitioning for storing objects of asocial-networking system.

FIG. 4 illustrates an example webpage of an online social network.

FIGS. 5A-5D illustrate example queries of the social network.

FIG. 6 illustrates an example method for generating search results inresponse to a search query with an inner constraint and an outerconstraint.

FIG. 7 illustrates an example method for parsing search queries usinginverse operators.

FIG. 8 illustrates an example method for generating search results basedon search intent.

FIG. 9 illustrates an example computer system.

DESCRIPTION OF EXAMPLE EMBODIMENTS

System Overview

FIG. 1 illustrates an example network environment 100 associated with asocial-networking system. Network environment 100 includes client system130, social-networking system 160, and third-party system 170 connectedto each other by a network 110. Although FIG. 1 illustrates a particulararrangement of client system 130, social-networking system 160,third-party system 170, and network 110, this disclosure contemplatesany suitable arrangement of client system 130, social-networking system160, third-party system 170, and network 110. As an example and not byway of limitation, two or more of client system 130, social-networkingsystem 160, and third-party system 170 may be connected to each otherdirectly, bypassing network 110. As another example, two or more ofclient system 130, social-networking system 160, and third-party system170 may be physically or logically co-located with each other in wholeor in part. Moreover, although FIG. 1 illustrates a particular number ofclient systems 130, social-networking systems 160, third-party systems170, and networks 110, this disclosure contemplates any suitable numberof client systems 130, social-networking systems 160, third-partysystems 170, and networks 110. As an example and not by way oflimitation, network environment 100 may include multiple client system130, social-networking systems 160, third-party systems 170, andnetworks 110.

This disclosure contemplates any suitable network 110. As an example andnot by way of limitation, one or more portions of network 110 mayinclude an ad hoc network, an intranet, an extranet, a virtual privatenetwork (VPN), a local area network (LAN), a wireless LAN (WLAN), a widearea network (WAN), a wireless WAN (WWAN), a metropolitan area network(MAN), a portion of the Internet, a portion of the Public SwitchedTelephone Network (PSTN), a cellular telephone network, or a combinationof two or more of these. Network 110 may include one or more networks110.

Links 150 may connect client system 130, social-networking system 160,and third-party system 170 to communication network 110 or to eachother. This disclosure contemplates any suitable links 150. Inparticular embodiments, one or more links 150 include one or morewireline (such as for example Digital Subscriber Line (DSL) or Data OverCable Service Interface Specification (DOCSIS)), wireless (such as forexample Wi-Fi or Worldwide Interoperability for Microwave Access(WiMAX)), or optical (such as for example Synchronous Optical Network(SONET) or Synchronous Digital Hierarchy (SDH)) links. In particularembodiments, one or more links 150 each include an ad hoc network, anintranet, an extranet, a VPN, a LAN, a WLAN, a WAN, a WWAN, a MAN, aportion of the Internet, a portion of the PSTN, a cellulartechnology-based network, a satellite communications technology-basednetwork, another link 150, or a combination of two or more such links150. Links 150 need not necessarily be the same throughout networkenvironment 100. One or more first links 150 may differ in one or morerespects from one or more second links 150.

In particular embodiments, client system 130 may be an electronic deviceincluding hardware, software, or embedded logic components or acombination of two or more such components and capable of carrying outthe appropriate functionalities implemented or supported by clientsystem 130. As an example and not by way of limitation, client system130 may include a computer system such as a desktop computer, notebookor laptop computer, netbook, a tablet computer, e-book reader, GPSdevice, camera, personal digital assistant (PDA), handheld electronicdevice, cellular telephone, smartphone, other suitable electronicdevice, or any suitable combination thereof. This disclosurecontemplates any suitable client systems 130. Client system 130 mayenable a network user at client system 130 to access network 110. Clientsystem 130 may enable its user to communicate with other users at otherclient systems 130.

In particular embodiments, client system 130 may include a web browser132, such as MICROSOFT INTERNET EXPLORER, GOOGLE CHROME or MOZILLAFIREFOX, and may have one or more add-ons, plug-ins, or otherextensions, such as TOOLBAR or YAHOO TOOLBAR. A user at client system130 may enter a Uniform Resource Locator (URL) or other addressdirecting the web browser 132 to a particular server (such as server162, or a server associated with third-party system 170), and the webbrowser 132 may generate a Hyper Text Transfer Protocol (HTTP) requestand communicate the HTTP request to server. The server may accept theHTTP request and communicate to client system 130 one or more Hyper TextMarkup Language (HTML) files responsive to the HTTP request. Clientsystem 130 may render a webpage based on the HTML files from the serverfor presentation to the user. This disclosure contemplates any suitablewebpage files. As an example and not by way of limitation, webpages mayrender from HTML files, Extensible Hyper Text Markup Language (XHTML)files, or Extensible Markup Language (XML) files, according toparticular needs. Such pages may also execute scripts such as, forexample and without limitation, those written in JAVASCRIPT, JAVA,MICROSOFT SILVERLIGHT, combinations of markup language and scripts suchas AJAX (Asynchronous JAVASCRIPT and XML), and the like. Herein,reference to a webpage encompasses one or more corresponding webpagefiles (which a browser may use to render the webpage) and vice versa,where appropriate.

In particular embodiments, social-networking system 160 may be anetwork-addressable computing system that can host an online socialnetwork. Social-networking system 160 may generate, store, receive, andsend social-networking data, such as, for example, user-profile data,concept-profile data, social-graph information, or other suitable datarelated to the online social network. Social-networking system 160 maybe accessed by the other components of network environment 100 eitherdirectly or via network 110. In particular embodiments,social-networking system 160 may include one or more servers 162. Eachserver 162 may be a unitary server or a distributed server spanningmultiple computers or multiple datacenters. Servers 162 may be ofvarious types, such as, for example and without limitation, web server,news server, mail server, message server, advertising server, fileserver, application server, exchange server, database server, proxyserver, another server suitable for performing functions or processesdescribed herein, or any combination thereof. In particular embodiments,each server 162 may include hardware, software, or embedded logiccomponents or a combination of two or more such components for carryingout the appropriate functionalities implemented or supported by server162. In particular embodiments, social-networking system 164 may includeone or more data stores 164. Data stores 164 may be used to storevarious types of information. In particular embodiments, the informationstored in data stores 164 may be organized according to specific datastructures. In particular embodiments, each data store 164 may be arelational, columnar, correlation, or other suitable database. Althoughthis disclosure describes or illustrates particular types of databases,this disclosure contemplates any suitable types of databases. Particularembodiments may provide interfaces that enable client system 130,social-networking system 160, or third-party system 170 to manage,retrieve, modify, add, or delete, the information stored in data store164.

In particular embodiments, social-networking system 160 may store one ormore social graphs in one or more data stores 164. In particularembodiments, a social graph may include multiple nodes—which may includemultiple user nodes (each corresponding to a particular user) ormultiple concept nodes (each corresponding to a particular concept)—andmultiple edges connecting the nodes. Social-networking system 160 mayprovide users of the online social network the ability to communicateand interact with other users. In particular embodiments, users may jointhe online social network via social-networking system 160 and then addconnections (i.e., relationships) to a number of other users ofsocial-networking system 160 whom they want to be connected to. Herein,the term “friend” may refer to any other user of social-networkingsystem 160 with whom a user has formed a connection, association, orrelationship via social-networking system 160.

In particular embodiments, social-networking system 160 may provideusers with the ability to take actions on various types of items orobjects, supported by social-networking system 160. As an example andnot by way of limitation, the items and objects may include groups orsocial networks to which users of social-networking system 160 maybelong, events or calendar entries in which a user might be interested,computer-based applications that a user may use, transactions that allowusers to buy or sell items via the service, interactions withadvertisements that a user may perform, or other suitable items orobjects. A user may interact with anything that is capable of beingrepresented in social-networking system 160 or by an external system ofthird-party system 170, which is separate from social-networking system160 and coupled to social-networking system 160 via a network 110.

In particular embodiments, social-networking system 160 may be capableof linking a variety of entities. As an example and not by way oflimitation, social-networking system 160 may enable users to interactwith each other as well as receive content from third-party systems 170or other entities, or to allow users to interact with these entitiesthrough an application programming interfaces (API) or othercommunication channels.

In particular embodiments, third-party system 170 may include one ormore types of servers, one or more data stores, one or more interfaces,including but not limited to APIs, one or more web services, one or morecontent sources, one or more networks, or any other suitable components,e.g., that servers may communicate with. A third-party system 170 may beoperated by a different entity from an entity operatingsocial-networking system 160. In particular embodiments, however,social-networking system 160 and third-party systems 170 may operate inconjunction with each other to provide social-networking services tousers of social-networking system 160 or third-party systems 170. Inthis sense, social-networking system 160 may provide a platform, orbackbone, which other systems, such as third-party systems 170, may useto provide social-networking services and functionality to users acrossthe Internet.

In particular embodiments, third-party system 170 may include athird-party content object provider. A third-party content objectprovider may include one or more sources of content objects, which maybe communicated to client system 130. As an example and not by way oflimitation, content objects may include information regarding things oractivities of interest to the user, such as, for example, movie showtimes, movie reviews, restaurant reviews, restaurant menus, productinformation and reviews, or other suitable information. As anotherexample and not by way of limitation, content objects may includeincentive content objects, such as coupons, discount tickets, giftcertificates, or other suitable incentive objects.

In particular embodiments, social-networking system 160 also includesuser-generated content objects, which may enhance a user's interactionswith social-networking system 160. User-generated content may includeanything a user can add, upload, send, or “post” to social-networkingsystem 160. As an example and not by way of limitation, a usercommunicates posts to social-networking system 160 from client system130. Posts may include data such as status updates or other textualdata, location information, photos, videos, links, music or othersimilar data or media. Content may also be added to social-networkingsystem 160 by a third-party through a “communication channel,” such as anewsfeed or stream.

In particular embodiments, social-networking system 160 may include avariety of servers, sub-systems, programs, modules, logs, and datastores. In particular embodiments, social-networking system 160 mayinclude one or more of the following: a web server, action logger,API-request server, relevance-and-ranking engine, content-objectclassifier, notification controller, action log,third-party-content-object-exposure log, inference module,authorization/privacy server, search module, ad-targeting module,user-interface module, user-profile store, connection store, third-partycontent store, or location store. Social-networking system 160 may alsoinclude suitable components such as network interfaces, securitymechanisms, load balancers, failover servers,management-and-network-operations consoles, other suitable components,or any suitable combination thereof. In particular embodiments,social-networking system 160 may include one or more user-profile storesfor storing user profiles. A user profile may include, for example,biographic information, demographic information, behavioral information,social information, or other types of descriptive information, such aswork experience, educational history, hobbies or preferences, interests,affinities, or location. Interest information may include interestsrelated to one or more categories. Categories may be general orspecific. As an example and not by way of limitation, if a user “likes”an article about a brand of shoes the category may be the brand, or thegeneral category of “shoes” or “clothing.” A connection store may beused for storing connection information about users. The connectioninformation may indicate users who have similar or common workexperience, group memberships, hobbies, educational history, or are inany way related or share common attributes. The connection informationmay also include user-defined connections between different users andcontent (both internal and external). A web server may be used forlinking social-networking system 160 to one or more client systems 130or one or more third-party system 170 via network 110. The web servermay include a mail server or other messaging functionality for receivingand routing messages between social-networking system 160 and one ormore client systems 130. An API-request server may allow third-partysystem 170 to access information from social-networking system 160 bycalling one or more APIs. An action logger may be used to receivecommunications from a web server about a user's actions on or offsocial-networking system 160. In conjunction with the action log, athird-party-content-object log may be maintained of user exposures tothird-party-content objects. A notification controller may provideinformation regarding content objects to client system 130. Informationmay be pushed to client system 130 as notifications, or information maybe pulled from client system 130 responsive to a request received fromclient system 130. Authorization servers may be used to enforce one ormore privacy settings of the users of social-networking system 160. Aprivacy setting of a user determines how particular informationassociated with a user can be shared. The authorization server may allowusers to opt in or opt out of having their actions logged bysocial-networking system 160 or shared with other systems (e.g.,third-party system 170), such as, for example, by setting appropriateprivacy settings. Third-party-content-object stores may be used to storecontent objects received from third parties, such as third-party system170. Location stores may be used for storing location informationreceived from client systems 130 associated with users.Advertisement-pricing modules may combine social information, thecurrent time, location information, or other suitable information toprovide relevant advertisements, in the form of notifications, to auser.

Social Graphs

FIG. 2 illustrates example social graph 200. In particular embodiments,social-networking system 160 may store one or more social graphs 200 inone or more data stores. In particular embodiments, social graph 200 mayinclude multiple nodes—which may include multiple user nodes 202 ormultiple concept nodes 204—and multiple edges 206 connecting the nodes.Example social graph 200 illustrated in FIG. 2 is shown, for didacticpurposes, in a two-dimensional visual map representation. In particularembodiments, social-networking system 160, client system 130, orthird-party system 170 may access social graph 200 and relatedsocial-graph information for suitable applications. The nodes and edgesof social graph 200 may be stored as data objects, for example, in adata store (such as a social-graph database). Such a data store mayinclude one or more searchable or queryable indexes of nodes or edges ofsocial graph 200.

In particular embodiments, a user node 202 may correspond to a user ofsocial-networking system 160. As an example and not by way oflimitation, a user may be an individual (human user), an entity (e.g.,an enterprise, business, or third-party application), or a group (e.g.,of individuals or entities) that interacts or communicates with or oversocial-networking system 160. In particular embodiments, when a userregisters for an account with social-networking system 160,social-networking system 160 may create a user node 202 corresponding tothe user, and store the user node 202 in one or more data stores. Usersand user nodes 202 described herein may, where appropriate, refer toregistered users and user nodes 202 associated with registered users. Inaddition or as an alternative, users and user nodes 202 described hereinmay, where appropriate, refer to users that have not registered withsocial-networking system 160. In particular embodiments, a user node 202may be associated with information provided by a user or informationgathered by various systems, including social-networking system 160. Asan example and not by way of limitation, a user may provide his or hername, profile picture, contact information, birth date, sex, maritalstatus, family status, employment, education background, preferences,interests, or other demographic information. In particular embodiments,a user node 202 may be associated with one or more data objectscorresponding to information associated with a user. In particularembodiments, a user node 202 may correspond to one or more webpages.

In particular embodiments, a concept node 204 may correspond to aconcept. As an example and not by way of limitation, a concept maycorrespond to a place (such as, for example, a movie theater,restaurant, landmark, or city); a website (such as, for example, awebsite associated with social-network system 160 or a third-partywebsite associated with a web-application server); an entity (such as,for example, a person, business, group, sports team, or celebrity); aresource (such as, for example, an audio file, video file, digitalphoto, text file, structured document, or application) which may belocated within social-networking system 160 or on an external server,such as a web-application server; real or intellectual property (suchas, for example, a sculpture, painting, movie, game, song, idea,photograph, or written work); a game; an activity; an idea or theory;another suitable concept; or two or more such concepts. A concept node204 may be associated with information of a concept provided by a useror information gathered by various systems, including social-networkingsystem 160. As an example and not by way of limitation, information of aconcept may include a name or a title; one or more images (e.g., animage of the cover page of a book); a location (e.g., an address or ageographical location); a website (which may be associated with a URL);contact information (e.g., a phone number or an email address); othersuitable concept information; or any suitable combination of suchinformation. In particular embodiments, a concept node 204 may beassociated with one or more data objects corresponding to informationassociated with concept node 204. In particular embodiments, a conceptnode 204 may correspond to one or more webpages.

In particular embodiments, a node in social graph 200 may represent orbe represented by a webpage (which may be referred to as a “profilepage”). Profile pages may be hosted by or accessible tosocial-networking system 160. Profile pages may also be hosted onthird-party websites associated with a third-party server 170. As anexample and not by way of limitation, a profile page corresponding to aparticular external webpage may be the particular external webpage andthe profile page may correspond to a particular concept node 204.Profile pages may be viewable by all or a selected subset of otherusers. As an example and not by way of limitation, a user node 202 mayhave a corresponding user-profile page in which the corresponding usermay add content, make declarations, or otherwise express himself orherself. As another example and not by way of limitation, a concept node204 may have a corresponding concept-profile page in which one or moreusers may add content, make declarations, or express themselves,particularly in relation to the concept corresponding to concept node204.

In particular embodiments, a concept node 204 may represent athird-party webpage or resource hosted by third-party system 170. Thethird-party webpage or resource may include, among other elements,content, a selectable or other icon, or other inter-actable object(which may be implemented, for example, in JavaScript, AJAX, or PHPcodes) representing an action or activity. As an example and not by wayof limitation, a third-party webpage may include a selectable icon suchas “like,” “check in,” “eat,” “recommend,” or another suitable action oractivity. A user viewing the third-party webpage may perform an actionby selecting one of the icons (e.g., “eat”), causing client system 130to send to social-networking system 160 a message indicating the user'saction. In response to the message, social-networking system 160 maycreate an edge (e.g., an “eat” edge) between a user node 202corresponding to the user and a concept node 204 corresponding to thethird-party webpage or resource and store edge 206 in one or more datastores.

In particular embodiments, a pair of nodes in social graph 200 may beconnected to each other by one or more edges 206. An edge 206 connectinga pair of nodes may represent a relationship between the pair of nodes.In particular embodiments, an edge 206 may include or represent one ormore data objects or attributes corresponding to the relationshipbetween a pair of nodes. As an example and not by way of limitation, afirst user may indicate that a second user is a “friend” of the firstuser. In response to this indication, social-networking system 160 maysend a “friend request” to the second user. If the second user confirmsthe “friend request,” social-networking system 160 may create an edge206 connecting the first user's user node 202 to the second user's usernode 202 in social graph 200 and store edge 206 as social-graphinformation in one or more of data stores 24. In the example of FIG. 2,social graph 200 includes an edge 206 indicating a friend relationbetween user nodes 202 of user “A” and user “B” and an edge indicating afriend relation between user nodes 202 of user “C” and user “B.”Although this disclosure describes or illustrates particular edges 206with particular attributes connecting particular user nodes 202, thisdisclosure contemplates any suitable edges 206 with any suitableattributes connecting user nodes 202. As an example and not by way oflimitation, an edge 206 may represent a friendship, family relationship,business or employment relationship, fan relationship, followerrelationship, visitor relationship, subscriber relationship,superior/subordinate relationship, reciprocal relationship,non-reciprocal relationship, another suitable type of relationship, ortwo or more such relationships. Moreover, although this disclosuregenerally describes nodes as being connected, this disclosure alsodescribes users or concepts as being connected. Herein, references tousers or concepts being connected may, where appropriate, refer to thenodes corresponding to those users or concepts being connected in socialgraph 200 by one or more edges 206.

In particular embodiments, an edge 206 between a user node 202 and aconcept node 204 may represent a particular action or activity performedby a user associated with user node 202 toward a concept associated witha concept node 204. As an example and not by way of limitation, asillustrated in FIG. 2, a user may “like,” “attended,” “played,”“listened,” “cooked,” “worked at,” or “watched” a concept, each of whichmay correspond to a edge type or subtype. A concept-profile pagecorresponding to a concept node 204 may include, for example, aselectable “check in” icon (such as, for example, a clickable “check in”icon) or a selectable “add to favorites” icon. Similarly, after a userclicks these icons, social-networking system 160 may create a “favorite”edge or a “check in” edge in response to a user's action correspondingto a respective action. As another example and not by way of limitation,a user (user “C”) may listen to a particular song (“Imagine”) using aparticular application (SPOTIFY, which is an online music application).In this case, social-networking system 160 may create a “listened” edge206 and a “used” edge (as illustrated in FIG. 2) between user nodes 202corresponding to the user and concept nodes 204 corresponding to thesong and application to indicate that the user listened to the song andused the application. Moreover, social-networking system 160 may createa “played” edge 206 (as illustrated in FIG. 2) between concept nodes 204corresponding to the song and the application to indicate that theparticular song was played by the particular application. In this case,“played” edge 206 corresponds to an action performed by an externalapplication (SPOTIFY) on an external audio file (the song “Imagine”).Although this disclosure describes particular edges 206 with particularattributes connecting user nodes 202 and concept nodes 204, thisdisclosure contemplates any suitable edges 206 with any suitableattributes connecting user nodes 202 and concept nodes 204. Moreover,although this disclosure describes edges between a user node 202 and aconcept node 204 representing a single relationship, this disclosurecontemplates edges between a user node 202 and a concept node 204representing one or more relationships. As an example and not by way oflimitation, an edge 206 may represent both that a user likes and hasused at a particular concept. Alternatively, another edge 206 mayrepresent each type of relationship (or multiples of a singlerelationship) between a user node 202 and a concept node 204 (asillustrated in FIG. 2 between user node 202 for user “E” and conceptnode 204 for “SPOTIFY”).

In particular embodiments, social-networking system 160 may create anedge 206 between a user node 202 and a concept node 204 in social graph200. As an example and not by way of limitation, a user viewing aconcept-profile page (such as, for example, by using a web browser or aspecial-purpose application hosted by the user's client system 130) mayindicate that he or she likes the concept represented by the conceptnode 204 by clicking or selecting a “Like” icon, which may cause theuser's client system 130 to send to social-networking system 160 amessage indicating the user's liking of the concept associated with theconcept-profile page. In response to the message, social-networkingsystem 160 may create an edge 206 between user node 202 associated withthe user and concept node 204, as illustrated by “like” edge 206 betweenthe user and concept node 204. In particular embodiments,social-networking system 160 may store an edge 206 in one or more datastores. In particular embodiments, an edge 206 may be automaticallyformed by social-networking system 160 in response to a particular useraction. As an example and not by way of limitation, if a first useruploads a picture, watches a movie, or listens to a song, an edge 206may be formed between user node 202 corresponding to the first user andconcept nodes 204 corresponding to those concepts. Although thisdisclosure describes forming particular edges 206 in particular manners,this disclosure contemplates forming any suitable edges 206 in anysuitable manner.

Indexing Based on Object-Type

FIG. 3 illustrates an example partitioning for storing objects ofsocial-networking system 160. A plurality of data stores 164 (which mayalso be called “verticals”) may store objects of social-networkingsystem 160. The amount of data (e.g., data for a social graph 200)stored in the data stores may be very large. As an example and not byway of limitation, a social graph used by Facebook, Inc. of Menlo Park,Calif. can have a number of nodes in the order of 10⁸, and a number ofedges in the order of 10¹⁰. Typically, a large collection of data suchas a large database may be divided into a number of partitions. As theindex for each partition of a database is smaller than the index for theoverall database, the partitioning may improve performance in accessingthe database. As the partitions may be distributed over a large numberof servers, the partitioning may also improve performance andreliability in accessing the database. Ordinarily, a database may bepartitioned by storing rows (or columns) of the database separately. Inparticular embodiments, a database maybe partitioned by based onobject-types. Data objects may be stored in a plurality of partitions,each partition holding data objects of a single object-type. Inparticular embodiments, social-networking system 160 may retrieve searchresults in response to a search query by submitting the search query toa particular partition storing objects of the same object-type as thesearch query's expected results. Although this disclosure describesstoring objects in a particular manner, this disclosure contemplatesstoring objects in any suitable manner.

In particular embodiments, each object may correspond to a particularnode of a social graph 200. An edge 206 connecting the particular nodeand another node may indicate a relationship between objectscorresponding to these nodes. In addition to storing objects, aparticular data store may also store social-graph information relatingto the object. Alternatively, social-graph information about particularobjects may be stored in a different data store from the objects.Social-networking system 160 may update the search index of the datastore based on newly received objects, and relationships associated withthe received objects.

In particular embodiments, each data store 164 may be configured tostore objects of a particular one of a plurality of object-types inrespective data storage devices 340. An object-type may be, for example,a user, a photo, a post, a comment, a message, an event listing, awebpage, an application, a user-profile page, a concept-profile page, auser group, an audio file, a video, an offer/coupon, or another suitabletype of object. Although this disclosure describes particular types ofobjects, this disclosure contemplates any suitable types of objects. Asan example and not by way of limitation, a user vertical P1 illustratedin FIG. 3 may store user objects. Each user object stored in the uservertical P1 may comprise an identifier (e.g., a character string), auser name, and a profile picture for a user of the online socialnetwork. Social-networking system 160 may also store in the uservertical P1 information associated with a user object such as language,location, education, contact information, interests, relationshipstatus, a list of friends/contacts, a list of family members, privacysettings, and so on. As an example and not by way of limitation, a postvertical P2 illustrated in FIG. 3 may store post objects. Each postobject stored in the post vertical P2 may comprise an identifier, a textstring for a post posted to social-networking system 160.Social-networking system 160 may also store in the post vertical P2information associated with a post object such as a time stamp, anauthor, privacy settings, users who like the post, a count of likes,comments, a count of comments, location, and so on. As an example andnot by way of limitation, a photo vertical P3 may store photo objects(or objects of other media types such as video or audio). Each photoobject stored in the photo vertical P3 may comprise an identifier and aphoto. Social-networking system 160 may also store in the photo verticalP3 information associated with a photo object such as a time stamp, anauthor, privacy settings, users who are tagged in the photo, users wholike the photo, comments, and so on. In particular embodiments, eachdata store may also be configured to store information associated witheach stored object in data storage devices 340.

In particular embodiments, objects stored in each vertical 164 may beindexed by one or more search indices. The search indices may be hostedby respective index server 330 comprising one or more computing devices(e.g., servers). The index server 330 may update the search indicesbased on data (e.g., a photo and information associated with a photo)submitted to social-networking system 160 by users or other processes ofsocial-networking system 160 (or a third-party system). The index server330 may also update the search indices periodically (e.g., every 24hours). The index server 330 may receive a query comprising a searchterm, and access and retrieve search results from one or more searchindices corresponding to the search term. In some embodiments, avertical corresponding to a particular object-type may comprise aplurality of physical or logical partitions, each comprising respectivesearch indices.

In particular embodiments, social-networking system 160 may receive asearch query from a PHP (Hypertext Preprocessor) process 310. The PHPprocess 310 may comprise one or more computing processes hosted by oneor more servers 162 of social-networking system 160. The search querymay be a text string or a structured query submitted to the PHP processby a user or another process of social-networking system 160 (orthird-party system 170).

More information on indexes and search queries may be found in U.S.patent application Ser. No. 13/560,212, filed 27 Jul. 2012, U.S. patentapplication Ser. No. 13/560,901, filed 27 Jul. 2012, and U.S. patentapplication Ser. No. 13/723,861, filed 21 Dec. 2012, each of which isincorporated by reference.

Typeahead Processes

In particular embodiments, one or more client-side and/or backend(server-side) processes may implement and utilize a “typeahead” featurethat may automatically attempt to match social-graph elements (e.g.,user nodes 202, concept nodes 204, or edges 206) to informationcurrently being entered by a user in an input form rendered inconjunction with a requested webpage (such as, for example, auser-profile page, a concept-profile page, a search-results webpage, oranother suitable page of the online social network), which may be hostedby or accessible in social-networking system 160. In particularembodiments, as a user is entering text to make a declaration, thetypeahead feature may attempt to match the string of textual charactersbeing entered in the declaration to strings of characters (e.g., names,descriptions) corresponding to user, concepts, or edges and theircorresponding elements in the social graph 200. In particularembodiments, when a match is found, the typeahead feature mayautomatically populate the form with a reference to the social-graphelement (such as, for example, the node name/type, node ID, edgename/type, edge ID, or another suitable reference or identifier) of theexisting social-graph element.

In particular embodiments, as a user types or otherwise enters text intoa form used to add content or make declarations in various sections ofthe user's profile page, home page, or other page, the typeahead processmay work in conjunction with one or more frontend (client-side) and/orbackend (server-side) typeahead processes (hereinafter referred tosimply as “typeahead process”) executing at (or within)social-networking system 160 (e.g., within servers 162), tointeractively and virtually instantaneously (as appearing to the user)attempt to auto-populate the form with a term or terms corresponding tonames of existing social-graph elements, or terms associated withexisting social-graph elements, determined to be the most relevant orbest match to the characters of text entered by the user as the userenters the characters of text. Utilizing the social-graph information ina social-graph database or information extracted and indexed from thesocial-graph database, including information associated with nodes andedges, the typeahead processes, in conjunction with the information fromthe social-graph database, as well as potentially in conjunction withvarious others processes, applications, or databases located within orexecuting within social-networking system 160, may be able to predict auser's intended declaration with a high degree of precision. However,social-networking system 160 can also provides user's with the freedomto enter essentially any declaration they wish, enabling users toexpress themselves freely.

In particular embodiments, as a user enters text characters into a formbox or other field, the typeahead processes may attempt to identifyexisting social-graph elements (e.g., user nodes 202, concept nodes 204,or edges 206) that match the string of characters entered in the user'sdeclaration as the user is entering the characters. In particularembodiments, as the user enters characters into a form box, thetypeahead process may read the string of entered textual characters. Aseach keystroke is made, the frontend-typeahead process may send theentered character string as a request (or call) to the backend-typeaheadprocess executing within social-networking system 160. In particularembodiments, the typeahead processes may communicate via AJAX(Asynchronous JavaScript and XML) or other suitable techniques, andparticularly, asynchronous techniques. In particular embodiments, therequest may be, or comprise, an XMLHTTPRequest (XHR) enabling quick anddynamic sending and fetching of results. In particular embodiments, thetypeahead process may also send before, after, or with the request asection identifier (section ID) that identifies the particular sectionof the particular page in which the user is making the declaration. Inparticular embodiments, a user ID parameter may also be sent, but thismay be unnecessary in some embodiments, as the user may already be“known” based on the user having logged into (or otherwise beenauthenticated by) social-networking system 160.

In particular embodiments, the typeahead process may use one or morematching algorithms to attempt to identify matching social-graphelements. In particular embodiments, when a match or matches are found,the typeahead process may send a response (which may utilize AJAX orother suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) or descriptions of thematching social-graph elements as well as, potentially, other metadataassociated with the matching social-graph elements. As an example andnot by way of limitation, if a user entering the characters “pok” into aquery field, the typeahead process may display a drop-down menu thatdisplays names of matching existing profile pages and respective usernodes 202 or concept nodes 204, such as a profile page named or devotedto “poker” or “pokemon”, which the user can then click on or otherwiseselect thereby confirming the desire to declare the matched user orconcept name corresponding to the selected node. As another example andnot by way of limitation, upon clicking “poker,” the typeahead processmay auto-populate, or causes the web browser 132 to auto-populate, thequery field with the declaration “poker”. In particular embodiments, thetypeahead process may simply auto-populate the field with the name orother identifier of the top-ranked match rather than display a drop-downmenu. The user may then confirm the auto-populated declaration simply bykeying “enter” on his or her keyboard or by clicking on theauto-populated declaration.

More information on typeahead processes may be found in U.S. patentapplication Ser. No. 12/763,162, filed 19 Apr. 2010, and U.S. patentapplication Ser. No. 13/556,072, filed 23 Jul. 2012, each of which isincorporated by reference.

Structured Search Queries

FIG. 4 illustrates an example webpage of an online social network. Inparticular embodiments, a user may submit a query to the social-networksystem 160 by inputting text into query field 450. A user of an onlinesocial network may search for information relating to a specific subjectmatter (e.g., users, concepts, external content or resource) byproviding a short phrase describing the subject matter, often referredto as a “search query,” to a search engine. The query may be anunstructured text query and may comprise one or more text strings (whichmay include one or more n-grams). In general, a user may input anycharacter string into query field 450 to search for content onsocial-networking system 160 that matches the text query.Social-networking system 160 may then search a data store 164 (or, inparticular, a social-graph database) to identify content matching thequery. The search engine may conduct a search based on the query phraseusing various search algorithms and generate search results thatidentify resources or content (e.g., user-profile pages, content-profilepages, or external resources) that are most likely to be related to thesearch query. To conduct a search, a user may input or send a searchquery to the search engine. In response, the search engine may identifyone or more resources that are likely to be related to the search query,each of which may individually be referred to as a “search result,” orcollectively be referred to as the “search results” corresponding to thesearch query. The identified content may include, for example,social-graph elements (i.e., user nodes 202, concept nodes 204, edges206), profile pages, external webpages, or any combination thereof.Social-networking system 160 may then generate a search-results webpagewith search results corresponding to the identified content and send thesearch-results webpage to the user. In particular embodiments, thesearch engine may limit its search to resources and content on theonline social network. However, in particular embodiments, the searchengine may also search for resources or contents on other sources, suchas third-party system 170, the internet or World Wide Web, or othersuitable sources. Although this disclosure describes queryingsocial-networking system 160 in a particular manner, this disclosurecontemplates querying social-networking system 160 in any suitablemanner.

In particular embodiments, the typeahead processes described herein maybe applied to search queries entered by a user. As an example and not byway of limitation, as a user enters text characters into a query filed450, a typeahead process may attempt to identify one or more user nodes202, concept nodes 204, or edges 206 that match the string of charactersentered into the query filed 450 as the user is entering the characters.As the typeahead process receives requests or calls including a stringor n-gram from the text query, the typeahead process may perform orcauses to be performed a search to identify existing social-graphelements (i.e., user nodes 202, concept nodes 204, edges 206) havingrespective names, types, categories, or other identifiers matching theentered text. The typeahead process may use one or more matchingalgorithms to attempt to identify matching nodes or edges. When a matchor matches are found, the typeahead process may send a response to theuser's client system 130 that may include, for example, the names (namestrings) of the matching nodes as well as, potentially, other metadataassociated with the matching nodes. The typeahead process may thendisplay a drop-down menu 400 that displays references to the matchingprofile pages (e.g., a name or photo associated with the page) of therespective user nodes 202 or concept nodes 204, and displays names ofmatching edges 206 that may connect to the matching user nodes 202 orconcept nodes 204, which the user can then click on or otherwise select,thereby confirming the desire to search for the matched user or conceptname corresponding to the selected node, or to search for users orconcepts connected to the matched users or concepts by the matchingedges. Alternatively, the typeahead process may simply auto-populate theform with the name or other identifier of the top-ranked match ratherthan display a drop-down menu 400. The user may then confirm theauto-populated declaration simply by keying “enter” on a keyboard or byclicking on the auto-populated declaration. Upon user confirmation ofthe matching nodes and/or edges, the typeahead process may send arequest that informs social-networking system 160 of the user'sconfirmation of a query containing the matching social-graph elements.In response to the sent request, social-networking system 160 mayautomatically (or alternately based on an instruction in the request)call or otherwise search a social-graph database for the matchingsocial-graph elements, or for social-graph elements connected to thematching social-graph elements as appropriate. Although this disclosuredescribes applying the typeahead processes to search queries in aparticular manner, this disclosure contemplates applying the typeaheadprocesses to search queries in any suitable manner.

In connection with search queries and search results, particularembodiments may utilize one or more systems, components, elements,functions, methods, operations, or steps disclosed in U.S. patentapplication Ser. No. 11/503,093, filed 11 Aug. 2006, U.S. patentapplication Ser. No. 12/977,027, filed 22 Dec. 2010, and U.S. patentapplication Ser. No. 12/978,265, filed 23 Dec. 2010, each of which isincorporated by reference.

Element Detection and Parsing Search Queries

FIGS. 5A-5D illustrate example queries of the online social network. Inparticular embodiments, in response to a text query received from afirst user (i.e., the querying user), social-networking system 160 mayparse the text query and identify portions of the text query thatcorrespond to particular social-graph elements. Social-networking system160 may then generate a set of structured queries, where each structuredquery corresponds to one of the possible matching social-graph elements.These structured queries may be based on strings generated by a grammarmodel, such that they are rendered in a natural-language syntax withreferences to the relevant social-graph elements. These structuredqueries may be presented to the querying user, who can then select amongthe structured queries to indicate that the selected structured queryshould be run by social-networking system 160. FIGS. 5A-5D illustratevarious example text queries in query field 450 and various structuredqueries generated in response in drop-down menus 400 (although othersuitable graphical user interfaces are possible). By providing suggestedstructured queries in response to a user's text query, social-networkingsystem 160 may provide a powerful way for users of the online socialnetwork to search for elements represented in the social graph 200 basedon their social-graph attributes and their relation to varioussocial-graph elements. Structured queries may allow a querying user tosearch for content that is connected to particular users or concepts inthe social graph 200 by particular edge-types. The structured queriesmay be sent to the first user and displayed in a drop-down menu 400(via, for example, a client-side typeahead process), where the firstuser can then select an appropriate query to search for the desiredcontent. Some of the advantages of using the structured queriesdescribed herein include finding users of the online social networkbased upon limited information, bringing together virtual indexes ofcontent from the online social network based on the relation of thatcontent to various social-graph elements, or finding content related toyou and/or your friends. Although this disclosure describes and FIGS.5A-5D illustrate generating particular structured queries in aparticular manner, this disclosure contemplates generating any suitablestructured queries in any suitable manner.

In particular embodiments, social-networking system 160 may receive froma querying/first user (corresponding to a first user node 202) anunstructured text query. As an example and not by way of limitation, afirst user may want to search for other users who: (1) are first-degreefriends of the first user; and (2) are associated with StanfordUniversity (i.e., the user nodes 202 are connected by an edge 206 to theconcept node 204 corresponding to the school “Stanford”). The first usermay then enter a text query “friends stanford” into query field 450, asillustrated in FIGS. 5A-5B. As the querying user enters this text queryinto query field 450, social-networking system 160 may provide varioussuggested structured queries, as illustrated in drop-down menus 400. Asused herein, an unstructured text query refers to a simple text stringinputted by a user. The text query may, of course, be structured withrespect to standard language/grammar rules (e.g. English languagegrammar). However, the text query will ordinarily be unstructured withrespect to social-graph elements. In other words, a simple text querywill not ordinarily include embedded references to particularsocial-graph elements. Thus, as used herein, a structured query refersto a query that contains references to particular social-graph elements,allowing the search engine to search based on the identified elements.Furthermore, the text query may be unstructured with respect to formalquery syntax. In other words, a simple text query will not necessarilybe in the format of a query command that is directly executable by asearch engine (e.g., the text query “friends stanford” could be parsedto form the query command “intersect(school(Stanford University),friends(me)”, which could be executed as a query in a social-graphdatabase). Although this disclosure describes receiving particularqueries in a particular manner, this disclosure contemplates receivingany suitable queries in any suitable manner.

In particular embodiments, social-networking system 160 may parse theunstructured text query (also simply referred to as a search query)received from the first user (i.e., the querying user) to identify oneor more n-grams. In general, an n-gram is a contiguous sequence of nitems from a given sequence of text or speech. The items may becharacters, phonemes, syllables, letters, words, base pairs, prefixes,or other identifiable items from the sequence of text or speech. Then-gram may comprise one or more characters of text (letters, numbers,punctuation, etc.) entered by the querying user. An n-gram of size onecan be referred to as a “unigram,” of size two can be referred to as a“bigram” or “digram,” of size three can be referred to as a “trigram,”and so on. Each n-gram may include one or more parts from the text queryreceived from the querying user. In particular embodiments, each n-grammay comprise a character string (e.g., one or more characters of text)entered by the first user. As an example and not by way of limitation,social-networking system 160 may parse the text query “friends stanford”to identify the following n-grams: friends; stanford; friends stanford.As another example and not by way of limitation, social-networkingsystem 160 may parse the text query “friends in palo alto” to identifythe following n-grams: friends; in; palo; alto; friends in; in palo;palo alto; friend in palo; in palo also; friends in palo alto. Inparticular embodiments, each n-gram may comprise a contiguous sequenceof n items from the text query. Although this disclosure describesparsing particular queries in a particular manner, this disclosurecontemplates parsing any suitable queries in any suitable manner.

In connection with element detection and parsing search queries,particular embodiments may utilize one or more systems, components,elements, functions, methods, operations, or steps disclosed in U.S.patent application Ser. No. 13/556,072, filed 23 Jul. 2012, U.S. patentapplication Ser. No. 13/732,101, filed 31 Dec. 2012, each of which isincorporated by reference.

Generating Structured Search Queries

In particular embodiments, social-networking system 160 may access acontext-free grammar model comprising a plurality of grammars. Eachgrammar of the grammar model may comprise one or more non-terminaltokens (or “non-terminal symbols”) and one or more terminal tokens (or“terminal symbols”/“query tokens”), where particular non-terminal tokensmay be replaced by terminal tokens. A grammar model is a set offormation rules for strings in a formal language. Although thisdisclosure describes accessing particular grammars, this disclosurecontemplates any suitable grammars.

In particular embodiments, social-networking system 160 may generate oneor more strings using one or more grammars. To generate a string in thelanguage, one begins with a string consisting of only a single startsymbol. The production rules are then applied in any order, until astring that contains neither the start symbol nor designatednon-terminal symbols is produced. In a context-free grammar, theproduction of each non-terminal symbol of the grammar is independent ofwhat is produced by other non-terminal symbols of the grammar. Thenon-terminal symbols may be replaced with terminal symbols (i.e.,terminal tokens or query tokens). Some of the query tokens maycorrespond to identified nodes or identified edges, as describedpreviously. A string generated by the grammar may then be used as thebasis for a structured query containing references to the identifiednodes or identified edges. The string generated by the grammar may berendered in a natural-language syntax, such that a structured querybased on the string is also rendered in natural language. A context-freegrammar is a grammar in which the left-hand side of each production ruleconsists of only a single non-terminal symbol. A probabilisticcontext-free grammar is a tuple

Σ, N, S, P

, where the disjoint sets Σ and N specify the terminal and non-terminalsymbols, respectively, with SδN being the start symbol. P is the set ofproductions, which take the form E→ξ(p), with EδN, ξε(Σ∪N)⁺, andp=Pr(E→ξ), the probability that E will be expanded into the string ξ.The sum of probabilities p over all expansions of a given non-terminal Emust be one. Although this disclosure describes generating strings in aparticular manner, this disclosure contemplates generating strings inany suitable manner.

In particular embodiments, social-networking system 160 may generate oneor more structured queries. The structured queries may be based on thenatural-language strings generated by one or more grammars, as describedpreviously. Each structured query may include references to one or moreof the identified nodes or one or more of the identified edges 206. Thistype of structured query may allow social-networking system 160 to moreefficiently search for resources and content related to the onlinesocial network (such as, for example, profile pages) by searching forcontent connected to or otherwise related to the identified user nodes202 and the identified edges 206. As an example and not by way oflimitation, in response to the text query, “show me friends of mygirlfriend,” social-networking system 160 may generate a structuredquery “Friends of Stephanie,” where “Friends” and “Stephanie” in thestructured query are references corresponding to particular social-graphelements. The reference to “Stephanie” would correspond to a particularuser node 202 (where social-networking system 160 has parsed the n-gram“my girlfriend” to correspond with a user node 202 for the user“Stephanie”), while the reference to “Friends” would correspond tofriend-type edges 206 connecting that user node 202 to other user nodes202 (i.e., edges 206 connecting to “Stephanie's” first-degree friends).When executing this structured query, social-networking system 160 mayidentify one or more user nodes 202 connected by friend-type edges 206to the user node 202 corresponding to “Stephanie”. As another exampleand not by way of limitation, in response to the text query, “friendswho like facebook,” social-networking system 160 may generate astructured query “Friends who like Facebook,” where “Friends,” “like,”and “Facebook” in the structured query are references corresponding toparticular social-graph elements as described previously (i.e., afriend-type edge 206, a like-type edge 206, and concept node 204corresponding to the company “Facebook”). Although this disclosuredescribes generating particular structured queries in a particularmanner, this disclosure contemplates generating any suitable structuredqueries in any suitable manner.

In particular embodiments, social-networking system 160 may rank thegenerated structured queries. The structured queries may be ranked basedon a variety of factors, such as, for example, in order of theprobability or likelihood that the identified nodes/edges referenced inthose structured queries match the search intent of the querying user,as determined by social-networking system 160. After ranking thestructured queries, social-networking system 160 may then send onlythose structured queries having a rank greater than a threshold rank(e.g., the top seven ranked queries may be sent to the querying user anddisplayed in a drop-down menu 300). In particular embodiments, the rankfor a structured query may be based on the degree of separation betweenthe user node 202 of the querying user and the particular social-graphelements referenced in the structured query. Structured queries thatreference social-graph elements that are closer in the social graph 200to the querying user (i.e., fewer degrees of separation between theelement and the querying user's user node 202) may be ranked more highlythan structured queries that reference social-graph elements that arefurther from the user (i.e., more degrees of separation). In particularembodiments, social-networking system 160 may rank the structuredqueries based on a search history associated with the querying user.Structured queries that reference social-graph elements that thequerying user has previously accessed, or are relevant to thesocial-graph elements the querying user has previously accessed, may bemore likely to be the target of the querying user's search query. Thus,these structured queries may be ranked more highly. As an example andnot by way of limitation, if querying user has previously visited the“Stanford University” profile page but has never visited the “Stanford,California” profile page, when determining the rank for structuredqueries referencing these concepts, social-networking system 160 maydetermine that the structured query referencing the concept node 204 for“Stanford University” has a relatively high rank because the queryinguser has previously accessed the concept node 204 for the school. Inparticular embodiments, a structured query may include a snippet ofcontextual information about one or more of the social-graph elementsreferenced in the structured query. In particular embodiments,social-networking system 160 may rank the structured queries based onadvertising sponsorship. An advertiser (such as, for example, the useror administrator of a particular profile page corresponding to aparticular node) may sponsor a particular node such that a structuredquery referencing that node may be ranked more highly. Although thisdisclosure describes ranking structured queries in a particular manner,this disclosure contemplates ranking structured queries in any suitablemanner.

In particular embodiments, social-networking system 160 may receive fromthe querying user a selection of one of the structured queries. Thenodes and edges referenced in the received structured query may bereferred to as the selected nodes and selected edges, respectively. Asan example and not by way of limitation, the web browser 132 on thequerying user's client system 130 may display the sent structuredqueries in a drop-down menu 300, as illustrated in FIGS. 5A-5D, whichthe user may then click on or otherwise select (e.g., by simply keying“enter” on his keyboard) to indicate the particular structured query theuser wants social-networking system 160 to execute. Upon selecting aparticular structured query, the user's client system 130 may call orotherwise instruct to social-networking system 160 to execute theselected structured query. Although this disclosure describes receivingselections of particular structured queries in a particular manner, thisdisclosure contemplates receiving selections of any suitable structuredqueries in any suitable manner.

More information on generating structured queries and grammar models maybe found in U.S. patent application Ser. No. 13/556,072, filed 23 Jul.2012, U.S. patent application Ser. No. 13/674,695, filed 12 Nov. 2012,and U.S. patent application Ser. No. 13/731,866, filed 31 Dec. 2012,each of which is incorporated by reference.

Parsing Search Queries and Generating Query Commands

In particular embodiments, social-networking system 160 may generate aquery command based on a structured query received from a querying user.The query command may then be used in a search against objects in a datastore 164 of the social-networking system 160. In particularembodiments, the query command may be provided for a search using searchindices for one or more data stores or verticals of social-networkingsystem 160. The query command may comprise one or more queryconstraints. Each query constraint may be identified bysocial-networking system 160 based on a parsing of the structured query.Each query constraint may be a request for a particular object-type. Inparticular embodiments, the query command may comprise query constraintsin symbolic expression or s-expression. Social-networking system 160 mayparse the structured query “Photos I like” to a query command(photos_liked_by:<me>). The query command (photos_liked_by: <me>)denotes a query for photos liked by a user (i.e., <me>, whichcorresponding to the querying user), with a single result-type of photo.The query constraint may include, for example, social-graph constraints(e.g., requests for particular nodes or nodes-types, or requests fornodes connected to particular edges or edge-types), object constraints(e.g., request for particular objects or object-types), locationconstraints (e.g., requests for objects or social-graph entitiesassociates with particular geographic locations), other suitableconstraints, or any combination thereof. In particular embodiments, theparsing of the structured query may be based on the grammar used togenerate the structured query. In other words, the generated querycommand and its query constraints may correspond to a particular grammar(or a sub-tree from a grammar forest). In particular embodiments, aquery command may comprise prefix and an object. The object maycorrespond to a particular node in the social graph 200, while theprefix may correspond to a particular edge 206 or edge-type (indicatinga particular type of relationship) connecting to the particular node inthe social graph 200. As an example and not by way of limitation, thequery command (pages_liked_by:<user>) comprises a prefix pages_liked_by,and an object <user>. In particular embodiments, social-networkingsystem 160 may execute a query command by traversing the social graph200 from the particular node along the particular connecting edges 206(or edge-types) to nodes corresponding to objects specified by querycommand in order to identify one or more search results. As an exampleand not by way of limitation, the query command (pages_liked_by:<user>)may be executed by social-networking system 160 by traversing the socialgraph 200 from a user node 202 corresponding to <user> along like-typeedges 206 to concept nodes 204 corresponding to pages liked by <user>.Although this disclosure describes generating particular query commandsin a particular manner, this disclosure contemplates generating anysuitable query commands in any suitable manner.

In particular embodiments, social-networking system 160 may identifyobjects associated with the online social network that satisfy theconstraints of a complex structured query having both an innerconstraint and an outer constraint, such as a nested search query. Theprocess of searching verticals 164 of objects associated withsocial-networking system 160 may be improved by using query hinting,where the outer query constraint is used when identifying objects thatmatch the inner query constraint. As an example and not by way oflimitation, a relatively complex structured query, such as “Photos offemales taken in Palo Alto”, as illustrated in FIG. 5C, could be parsedso that a users vertical 164 is first searched to identify users who arefemale and then to intersect those results with the results from aphotos vertical 164 of photos taken in Palo Alto. The user verticalmight produce results corresponding to hundred, or even thousands, offemale users, none of whom may be tagged in photos taken in Palo Alto,such that the intersect of these results produces no search results.Alternatively, this structured query could be parsed using queryhinting, so that the structured query “Photos of females taken in PaloAlto” could be parsed, for example, so that a user vertical is searchedto identify users who are female, and by using an operator that allowsarguments to be absents from some results, such as a “weak and” (WAND)operator, to identify at least some female user who also are tagged inphotos in Palo Alto. Next, the photos vertical 164 could be searched toidentify photos taken in Palo Alto where any of the identified femaleusers are tagged. In this way, the search of the vertical correspondingto objects requested by the outer constraint is more likely to generateresults that satisfy the search query. This may also allowsocial-networking system 160 to produce better search results and mayimprove the processing efficiency for generating these results. Inparticular embodiments, the results from the vertical searched inresponse to the inner query constraint could be scored or ranked, andthose scores could be used when scoring the objects identified from thevertical searched in response to the outer query constraint. Althoughthis disclosure describes identifying objects matching a structuredquery a particular manner, this disclosure contemplates identifyingobjects matching a structured query in any suitable manner.

In particular embodiments, social-networking system 160 may generate aquery command comprising an inner query constraint and an outer queryconstraint. The inner query constraint may comprise a request for one ormore search results of a first object-type, and the outer queryconstraint may comprise a request for one or more search results of asecond object type. Each query constraint may be for one or more nodesconnected to one or more of the selected nodes referenced in thestructured query by one or more of the selected edges referenced in thestructured query. The query command with one or more query constraintsmay comprise nested queries in s-expression. As an example and not byway of limitation, social-networking system 160 may convert thestructured query “Pages liked by my friends”, to a nested query such as,for example, (pages_liked_by: (friends_of: <me>)). The nested searchquery (pages_liked_by: (friends_of: <me>)) comprises an inner queryconstraint (friends_of: <me>) nested in an outer query constraint(pages_liked_by:<user>). The inner query constraint (friends_of: <me>)denotes a query for first-degree friends of a user (i.e., <me>), with asingle result-type of user. The outer query constraint (pages_liked_by:<user>) denotes a query for pages liked by a user, with a singleresult-type of page. As another example and not by way of limitation,social-networking system 160 may convert the structured query “Photos ofpeople named Tom”, to a nested query such as, for example, (photos_of:(name: tom)). The nested query (photos_of: (name: tom)) comprises aninner query constraint (name: tom) nested in an outer query constraint(photos_of: <user>). The inner query constraint denotes a query forusers whose name matching “Tom”, with a single result-type of user. Theouter query constraint (photos_of: <user>) denotes a query for photosthat a user is tagged in, with a single result-type of photo. As yetanother example, social-networking system 160 may convert the structuredquery “People who wrote posted liked by Bill”, to a nested query suchas, for example, (extract author (term posts_liked_by: <Bill>)). Thequery command may request (with an extract operator) a search result ofone or more authors for posts that are liked by the user “Bill”. Thenested query may include an inner query (term posts_liked_by: <Bill>)corresponding to a search term that requests search results in poststhat are liked by the user <Bill>. That is, the outer constraintrequests a first search result of a first object-type (user), while theinner constraint requests second search results of a second object-type(post). Although this disclosure describes parsing queries in aparticular manner, this disclosure contemplates parsing queries in anysuitable manner.

In particular embodiments, social-networking system 160 may identify oneor more nodes matching one or more query constraints of the querycommand. Social-networking system 160 may search one or more data stores164 to identify one or more objects stored in the data stores thatsatisfy one or more constraints of a query command. As an example andnot by way of limitation, social-networking system 160 may submit thequery constraint (photos_liked_by: <me>) (with photo result-type) tophoto vertical P3. Social-networking system 160 may access index server330 of photo vertical 164, causing index server 330 to return resultsfor the query constraint (photos_liked_by: <me>). In particularembodiments, social-networking system 160 may, for each query constraintof a query command, access and retrieve search results from at least oneof the data stores 164. The accessed data store 164 may be configured tostore objects of the object type of specified by the particular queryconstraint. Social-networking system 160 may then aggregate searchresults of the respective query constraints. As an example and not byway of limitation, the nested query (photos_of:(name: tom)) comprisesthe inner query constraint (name: tom) with a single result-type ofuser, and the outer query constraint (photos_of:<user>) with a singleresult-type of photo. Social-networking system 160 may then rearrangethe nested query and first submit the inner query constraint (name: tom)(with user result-type) to user vertical P1. Social-networking system160 may access index server 330 of user vertical P1, causing indexserver 330 to return search results of users <17>, <31>, and <59> (eachrepresented by an user identifier). That is, each user of <17>, <31>,and <59> may have a name matching “tom.” Social-networking system 160may then re-write the nested query to an OR combination of queries(photos_of: <17>), (photos_of: <31>), and (photos_of: <59>)), each witha result-type of photo. Social-networking system 160 may then submit thequeries (photos_of: <17>), (photos_of: <31>), and (photos of: <59>) tophoto vertical P3. Social-networking system 160 may access index server330 of photo vertical P3, causing index server 330 to return searchresults of photos for the queries (photos_of: <17>), (photos_of: <31>),and (photos_of: <59>). In particular embodiments, social-networkingsystem 160 may aggregate the search results by performing an ORoperation on the search results. As an example and not by way oflimitation, search results for the search query (photos_of: <17>) may be<1001> and <1002> (each represented by a photo identifier). Searchresults for the search query (photos_of: <31>) may be <1001>, <1326>,<9090>, and <5200>. Search results for the search query (photos_of:<59>) may be <9090> and <7123>. Social-networking system 160 may performan OR operation on the search results, yielding final search results of<1001>, <1002>, <1326>, <9090>, <5200>, and <7123>. Although thisdisclosure describes identifying particular search results in aparticular manner, this disclosure contemplates identifying any suitablesearch results in any suitable manner.

In particular embodiments, when identifying matching nodes for a queryconstraint, social-networking system 160 may only identify up to athreshold number of matching nodes in a particular vertical 164. Thisthreshold number of matching objects may then be retrieved as searchresults. The threshold number may be chosen to enhance search quality orto optimize the processing of search results. As an example and not byway of limitation, social-networking system 160 may only identify thetop N matching objects in a photos vertical 164 in response to a querycommand requesting photo objects. The top N photo objects may bedetermined by a static ranking of the photo objects in a search indexcorresponding to the photo vertical. In particular embodiments, the topN identified results may be re-ranked based on the search query itself.As an example and not by way of limitation, if N is 1000, the top 1000photo objects (as determined by a static ranking) may be identified.These 1000 photo objects may then be ranked based on one or more factors(e.g., match to the search query or other query constraints,social-graph affinity, search history, etc.), and the top 20 results maythen be generated as search results for presentation to the queryinguser. In particular embodiments, the top results after one or morerounds of rankings may be sent to an aggregator 320 for a final round ofranking, where results may be reordered, redundant results may bedropped, or any other type of results-processing may occur beforepresentation to the querying user. Although this disclosure describesidentifying particular numbers of search result, this disclosurecontemplates identifying any suitable numbers of search results.Furthermore, although this disclosure describes ranking search resultsin a particular manner, this disclosure contemplates ranking searchresults in any suitable manner.

In particular embodiments, social-networking system 160 may generate aquery command comprising a “weak and” operator (WAND). The WAND operatormay allow one or more of its arguments (e.g., keywords or logicalexpressions comprising operators and keywords) within the query commandto be absent a specified number of times or percentage of time.Social-networking system 160 may take into account social-graph elementsreferenced in the structured query when generating a query command witha WAND operator by adding implicit query constraints that referencethose social-graph elements. This information from the social graph 200may be used to diversify search results using the WAND operator. As anexample and not by way of limitation, if a user enters the structuredquery “Coffee shops in Palo Alto”, social-networking system 160 maygenerate a query command such as, for example:

(WAND  category: <coffee shop>  location: <Palo Alto> : optional-weight0.3).In this example, instead of requiring that search results always matchboth the (category: <coffee shop>) and (location: <Palo Alto>) portionsof the query command, the Palo Alto portion of the query is optionalizedwith a weight of 0.3. In this case, this means that 30% of the searchresults must match the (location: <Palo Alto>) term (i.e., must beconnected by an edge 206 to the concept node 204 corresponding to thelocation “Palo Alto”), and the remaining 70% of the search results mayomit that term. Thus, if N is 100, then 30 coffee shop results must havea location of “Palo Alto”, and 70 coffee shop results may come fromanywhere (e.g. from the global top 100 coffee shops determined by astatic ranking of coffee shops). In particular embodiments, the term(category: <coffee shop>) may also be assigned an optional weight, suchthat the search results need not even always match the social-graphelement for “Coffee shop” and some results may be chosen bysocial-networking system 160 to be any object (e.g. place).

In particular embodiments, social-networking system 160 may generate aquery command comprising a “strong or” operator (SOR). The SOR operatormay require one or more of its arguments (e.g., keywords or logicalexpressions comprising operators and keywords) within the query commandto be present a specified number of times or percentage of time.Social-networking system 160 may take into account social-graph elementsreferenced in the structured query when generating a query command witha WAND operator by adding implicit query constraints that referencethose social-graph elements. This information from the social graph 200may be used to diversify search results using the SOR operator. As anexample and not by way of limitation, if a user enters the structuredquery “Coffee shops in Palo Alto or Redwood City”, social-networkingsystem 160 may translate a query command such as, for example:

(AND category: <coffee shop> (SOR location: <Palo Alto>: optional-weight0.4 location: <Redwood City> : optional-weight 0.3)).In this example, instead of allowing search results that match eitherthe (location: <Palo Alto>) or (location: <Redwood City>) portions ofthe query command, the Palo Alto portion of the query is optionalizedwith a weight of 0.4 and the Redwood City portion of the query isoptionalized with a weight of 0.3. In this case, this means that 40% ofthe search results must match the (location:<Palo Alto>) term (i.e., areconcept nodes 204 corresponding to “coffee shops” that are eachconnected by an edge 206 to the concept node 204 corresponding to the(location <Palo Alto>), and 30% of the search results must match the(location:<Redwood City>) term, with the remainder of the search resultmatching either the Palo Alto or Redwood City constraints (or both, ifappropriate in certain cases). Thus, if N is 100, then 40 coffee shopresults must have a location of “Palo Alto”, 30 coffee shop results musthave a location of “Redwood City”, and 30 coffee shops may come fromeither location.

In particular embodiments, in response to a query command comprising aninner and outer query constraint, social-networking system 160 mayidentify a first set of nodes matching an inner query constraint and atleast in part matching an outer query constraint. In this way, theprocess of searching verticals 164 of objects associated withsocial-networking system 160 may be improved by generating querycommands that use query hinting, where the outer query constraint isused when identifying objects that match the inner query constraint.This may also allow social-networking system 160 to produce bettersearch results and may improve the processing efficiency for generatingthese results. The query command may be formed using, for example, WANDor SOR operators, such that the query command requires a first number ofidentified nodes to match the inner constraint, or match the inner orouter constraint, and a second number of identified nodes to match bothconstraints or just the outer constraint, or any combination thereof.The first and second numbers may be, for example, a real number, apercentage, or a fraction. Although this disclosure describesidentifying particular social-graph elements as matching particularquery constraints in a particular manner, this disclosure contemplatesidentifying any suitable social-graph elements as matching any suitablequery constraints in any suitable manner.

In particular embodiments, identifying a first set of nodes matching theinner query constraint and at least in part matching the outer queryconstraint may comprise identifying a first number of nodes matching atleast the inner query constraint and identify a second number of nodesmatching both the inner query constraint and the outer query constraint.The query command may be formed such that it requires that at least afirst number of search results returned in response to the query commandmatch both the inner and outer query constraints, while permitting atleast a second number of the search results to match only the innerconstraint (e.g. as in the case of using the WAND operator). As anexample and not by way of limitation, in response to the structuredquery “Photos of females taken in Palo Alto”, social-networking system160 may generate a query command to resolve the inner query constraintsuch as, for example,

(WAND  (term gender_to_user: <female>)  (term photo_place_tag_to_user:<Palo Alto> : optional-weight 0.9)).In this case, the inner constraint would be to identify female users,and the outer constraint would be to identify photos of the identifiedfemale users taken in the city of Palo Alto. When searching the usersvertical 164 to identify matching user nodes 202 for the innerconstraint, rather than just specifying that female users should beidentified (which may identify numerous female users who are not taggedin any photos in Palo Alto), the query command specifies that at least90% of the user results must be females who are also tagged in photos inPalo Alto. In this way, the index is denormalized by adding theadditional constraint (term photo_place_tag_to_user: <PaloAlto>:optional-weight 0.9). The remaining 10% of the user results needonly match the “female” constraint. Thus, query hinting is used so thatthe outer query constraint is considered when resolving the inner queryconstraint. Next, the photos vertical 164 could be searched to identifyphotos taken in Palo Alto where any of the previously identified femaleusers are tagged. Because 90% of the nodes identified by the search ofthe users vertical 164 are already identified as being female users whohave been tagged in photos in Palo Alto, the search of the photosvertical 164 is more likely to be able to produce a relatively largenumber of photos where the identified females are tagged. Although thisdisclosure describes identifying particular social-graph elements asmatching particular query constraints in a particular manner, thisdisclosure contemplates identifying any suitable social-graph elementsas matching any suitable query constraints in any suitable manner.

In particular embodiments, identifying a first set of nodes matching theinner query constraint and at least in part matching the outer queryconstraint may comprise identifying a first number of nodes where eachnode matches either the inner or outer query constraints and identify asecond number of nodes where each node matches both the inner and outerquery constraints. The query command may be formed such that at least afirst number of search results returned in response to the query commandmatch the inner constraint, and that at least a second number of searchresults match the outer constraint, with the remainder matching eitherthe inner constraint or the outer constraint (e.g. as in the case ofusing the SOR operator). As another example and not by way oflimitation, in response to the structured query “Photos of Mark andwomen”, social-networking system 160 may generate a query command toresolve the inner query constraint such as, for example,

(WAND  (term gender_to_user:<female>)  (SOR: optional-weight 0.8   (termfriend_of:<Mark>: optional-weight: 0.7)   (termnon_friend_in_same_photo:<Mark> :optional-weight: 0.1))).In this case, the inner constraint would be to identify female users,and the outer constraint would be to identify photos of the identifiedfemale users taken with the user “Mark”. When searching the usersvertical 164 to identify matching user nodes 202 for the innerconstraint, rather than just specifying that female users should beidentified (which may identify numerous female users who are not taggedin any photos with the user “Mark”), the query command specifies that atleast 80% of the user results must be females who also match one of theconstraints in the SOR constraint, where the SOR constraint specifiesthat 70% of the user results must match the (friend_of: <Mark>)constraint, and 10% of the user results must match the(non_friend_in_same_photo: <Mark>) constraint, with the remainder of thesearch results matching either constraint (or both, if appropriate).Thus, if N is 100, then 20 user results must simply be female, 56 userresults must be females who are friends of the user “Mark”, 8 userresults must be females who are non-friends of “Mark” who happen to betagged in a photo with “Mark”, and 16 user result must be female andeither friends of “Mark” or non-friends tagged in a photo with “Mark”.In this way, the index is denormalized by adding various additionalconstraints, which may also help generate diversity of results. Thus,query hinting is used so that the outer query constraint (i.e., being ina photo with the user “Mark”) is considered when resolving the innerquery constraint. Next, the photos vertical 164 could be searched toidentify photos taken with the user “Mark” where any of the previouslyidentified female users are tagged. Because 80% of the nodes identifiedby the search of the users vertical 164 are already identified as beingfemale users with some type of relationship to the user “Mark”, thesearch of the photos vertical 164 is more likely to be able to producephotos that satisfy the search query. Although this disclosure describesidentifying particular social-graph elements as matching particularquery constraints in a particular manner, this disclosure contemplatesidentifying any suitable social-graph elements as matching any suitablequery constraints in any suitable manner.

In particular embodiments, social-networking system 160 may score one ormore nodes identified as matching a query constraint. The identifiednodes may be scored in any suitable manner. When a query commandincludes a plurality of query constraints, social-networking system 160may score the nodes matching each query constraint independently orjointly. Social-networking system 160 may score the first set ofidentified nodes by accessing a data store 164 corresponding to theobject-type of the identified nodes. As an example and not by way oflimitation, when generating identified nodes matching the queryconstraint (extract authors: (term posts_liked_by: <Mark>)),social-networking system 160 may identify the set of users (<Tom>,<Dick>, <Harry>) in the user vertical 164. Social-networking system 160may then score the users <Tom>, <Dick>, and <Harry> based on theirrespective social-affinity with respect to the user <Mark>. For example,social-networking system 160 of the post vertical 164 may then score theidentified nodes of users <Tom>, <Dick>, and <Harry> based on a numberof posts in the list of posts liked by the user <Mark>. The users <Tom>,<Dick>, and <Harry> may have authored the following posts liked by theuser <Mark>: <post 1>, <post 2>, <post 3>, <post 4>, <post 5>, <post 6>.If user <Dick> authored posts <post 1>, <post 2>, <post 3>, user <Tom>authored posts <post 5> and <post 6>, and user <Harry> authored post<post 4>, social-networking system 160 may score user <Dick> as highestsince his authored most of the posts in the list of posts liked by theuser <Mark>, with <Tom> and <Harry> having consecutively lower scores.As another example and not by way of limitation, using the priorexample, social-networking system 160 may access a forward index thatmaps a post to a count of likes of the post. The index server may accessthe forward index and retrieve counts of likes for each post of the listof posts liked by the user <Mark>. The index server may score the postsin the list of posts (i.e., <post 1>, <post 2>, <post 3>, <post 4>,<post 5>, <post 6>) based on respective counts of likes, and return tosocial-networking system 160 authors of top scored posts (e.g., top 3scored or most liked posts) as the first identified node. After eachappropriate scoring factor is considered for a particular identifiednode, an overall score for the identified node may be determined. Basedon the scoring of the nodes, social-networking system 160 may thengenerate one or more sets of identified nodes. As an example and not byway of limitation, social-networking system 160 may only generate a setof identified nodes corresponding to nodes having a score greater than athreshold score. As another example and not by way of limitation,social-networking system 160 may rank the scored nodes and then onlygenerate a set of identified nodes corresponding to nodes having a rankgreater than a threshold rank (e.g., top 10, top 20, etc.). Althoughthis disclosure describes scoring matching nodes in a particular manner,this disclosure contemplates scoring matching nodes in any suitablemanner.

In particular embodiments, social-networking system 160 may score asecond set of nodes based at least in part on the scores of a first setof nodes. The search results may be scored in any suitable manner. Whena query command includes a plurality of query constraints,social-networking system 160 may score the nodes matching each queryconstraint separately. Alternatively, social-networking system 160 mayutilize the score from one set of nodes when scoring one or more othersets of nodes. For a query command with an inner constraint and an outerconstraint, social-networking system 160 may identify a first set ofnodes matching the inner query constraint and then score these nodes.Social-networking system 160 may then identify a second set of nodesmatching the outer query constraint, and score the second set of nodesbased at least in part on the scores of the first set of nodes. As anexample and not by way of limitation, in response to the structuredquery “Pages liked by my friends”, social-networking system 160 maygenerate a query command such as, for example, (pages_liked_by:(friends_of: <me>)). Social-networking system 160 may first resolve theinner query constraint by accessing a users vertical 164 and identifyinga first set of nodes corresponding to the inner query constraint, whichrequests users that are friends of the querying user. This first set ofusers may comprise (<Tom>, <Dick>, <Harry>), who may each correspond toa respective user nodes 202 that is connected by a friend-type edge 206to the user node 202 of the querying user. Social-networking system 160may then score this first set of nodes in any suitable manner. Forexample, the set of users may be scored based on their respectivesocial-graph affinity with respect to the querying user, where the user“Dick” may have the best affinity in the set, “Harry” may have thesecond-best affinity, and “Tom” may have the worst affinity in the set.Next, social-networking system 160 may resolve the outer queryconstraint by accessing a pages vertical 164 and identify a second setof nodes corresponding to the outer query constraint, which requestspages liked by the users in the first set (i.e., pages corresponding toconcept nodes 204 that are connected by like-type edges 206 to at leastone of the user nodes 202 corresponding to the users “Tom”, “Dick”, and“Harry”). The users “Tom”, “Dick”, and “Harry” may have liked thefollowing pages: (<page 1>, <page 2>, <page 3>, <page 4>, <page 5>).Social-networking system 160 may then score this second set of nodes inany suitable manner. For example, the set of pages may be scored basedon their overall popularity on the online social network, where pagesthat are more globally popular are scored respectively better than pagesthat are less popular. The set of pages may also be scored based atleast in part on the scores of the first set of nodes. For example,<page 1> may be liked by “Tom”, <page 2> may be liked by “Dick”, <page3> may be liked by “Harry”, <page 4> may be liked by “Tom” and “Harry”,and <page 5> may be liked by “Tom”, “Dick”, and “Harry”. In this case,social-networking system 160 may score the second set of nodes based onin part of the first set of node by improving the scores of pages likedby users with better affinities and downgrading (or at least improvingless) the scores of pages liked by users with worse affinities. Forexample, since the user “Dick” has the best affinity with respect to thequerying user, the pages liked by “Dick” (which are <page 2>, and <page5>) may all have their scores improved. Similarly, since the user “Tom”has the worst affinity with respect to the querying user, pages liked by“Tom” (which are <page 1>, <page 4>, and <page 5>) may all have theirscored downgraded (or at least not improved as much). After eachappropriate scoring factor is considered for a particular identifiednode, an overall score for the identified node may be determined. Basedon the scoring of the nodes, social-networking system 160 may thengenerate one or more sets of identified nodes. As an example and not byway of limitation, social-networking system 160 may only generate a setof identified nodes corresponding to nodes having a score greater than athreshold score. As another example and not by way of limitation,social-networking system 160 may rank the scored nodes and then onlygenerate a set of identified nodes corresponding to nodes having a rankgreater than a threshold rank (e.g., top 10, top 20, etc.). Althoughthis disclosure describes scoring nodes in a particular manner, thisdisclosure contemplates scoring nodes in any suitable manner.

In particular embodiments, social-networking system 160 may generate oneor more search results based on a first set of nodes identified asmatching the inner query constraint and at least in part matching theouter query constraint, and further based on a second set of nodesidentified as matching the outer query constraint. Each search resultmay correspond to a node of the plurality of nodes. As discussedpreviously, the nodes identified as matching the inner query constraint,which may be identifying using query hinting from the outer queryconstraint, may then be used as a basis for identifying nodes matchingthe outer query constraint. The nodes identified as matching the outerquery constraint may be scored (and possibly ranked), and then one ormore (e.g., a threshold number) may be generated as search result todisplay to the user. The search results may be presented and sent to thequerying user as a search-results page, where the generated searchresults are displayed. As an example and not by way of limitation, inresponse to the structured query “Photos of females taken in Palo Alto”,as illustrated in FIG. 5C, social-networking system 160 may identify afirst set of nodes matching the inner query constraint using queryhinting. In this example, the inner constraint requests users who arefemale, and where query hinting may be used so that a number of theusers identified in the first set are users who are also tagged inphotos in the city of Palo Alto. Next, social-networking system 160 mayidentify a second set of nodes matching the outer query constraint. Inthis example, the outer constraint requests photos of users in the firstset that are taken in Palo Alto. One or more search results may then begenerated based on the nodes identified in the second set of nodes. Thegenerated search results may then be sent and displayed to the queryinguser as part of a search-results page corresponding to the structuredquery “Photos of females taken in Palo Alto”. The search-results pagemay display the search results, for example, as thumbnails of the photoscorresponding to the nodes identified in the second set. Although thisdisclosure describes generating particular search results in aparticular manner, this disclosure contemplates generating any suitablesearch results in any suitable manner.

FIG. 6 illustrates an example method 600 for generating search resultsin response to a search query with an inner constraint and an outerconstraint. The method may begin at step 610, where social-networkingsystem 160 may access a social graph 200 comprising a plurality of nodes(e.g., user nodes 202 or concept nodes 204) and a plurality of edges 206connecting the nodes. Each edge between two nodes may represent a singledegree of separation between them. The nodes may comprise a first node(e.g., a first user node 202) corresponding to a first user associatedwith the online social network. The nodes may also comprise a pluralityof second nodes that each correspond to a concept or second userassociate with the online social network. At step 620, social-networkingsystem 160 may receive from the first user a structured query comprisingreferences to one or more selected nodes from the plurality of nodes andone or more selected edges from the plurality of edges. At step 630,social-networking system 160 may generate a query command based on thestructured query. The query command comprises a first query constraintand a second query constraint (e.g., an inner constraint and an outerconstraint). At step 640, social-networking system 160 may identify afirst set of nodes matching the first query constraint and at least inpart matching the second query constraint. At step 650,social-networking system 160 may identify a second set of nodes matchingthe second query constraint. At step 660, social-networking system 160may generate one or more search results based on the first and secondsets of nodes. Each search result may correspond to a node of theplurality of nodes. Particular embodiments may repeat one or more stepsof the method of FIG. 6, where appropriate. Although this disclosuredescribes and illustrates particular steps of the method of FIG. 6 asoccurring in a particular order, this disclosure contemplates anysuitable steps of the method of FIG. 6 occurring in any suitable order.Moreover, although this disclosure describes and illustrates particularcomponents, devices, or systems carrying out particular steps of themethod of FIG. 6, this disclosure contemplates any suitable combinationof any suitable components, devices, or systems carrying out anysuitable steps of the method of FIG. 6.

In particular embodiments, social-networking system 160 may parsestructured search queries and generate query commands that includeinverse operators. The process of searching verticals 164 of objectsassociated with social-networking system 160 may be improved by usinginverse operators, where one of the query constraints may be modified toinclude its inverse constraint. When parsing a structured query havingboth an inner query constraint and an outer query constraint, such as anested search query, the typical processing of the query may produce aninadequate number of search results. This may happen, for example,because the inner query constraint produces too many results, reducingthe likelihood that any of them will satisfy the outer query constraint.As an example and not by way of limitation, a relatively complexstructured query, such as “Photos of me liked by people in China”, asillustrated in FIG. 5D, could be parsed as (intersect(photos_of: <me>,photos_liked_by: (users_from: <China>))). When this parsing is executed,it would first search a users vertical 164 to identify users located inChina and then interest those results with the results from a photovertical 164 to identify photos of the querying user that are liked byone of the identified users in China. However, the first search of theusers vertical 164 might produce results corresponding to hundreds, oreven thousands, of users in China, none of whom may have liked anyphotos of the querying user. Alternatively, this structured query couldbe parsed using an inverse operator. In particular embodiments, certainoperators may correspond to particular inverse operators. As an exampleand not by way of limitation, instead of using a “liked_by” operator,the structured query may instead be parsed to include its inverseoperator, i.e., a “likers_of” operator. In other words, instead ofsearching for photos liked by users in China, to instead searches for“likers_of” photos of the querying user. For example, the structuredquery “Photos of me liked by people in China” could be parsed as(intersect(photos_of: <me>, photos_liked_by:(intersect(likers_of(photos_of: <me>), users_from: <China>)))). Thiswould change the processing order of the query so that first the photosvertical 164 is access to identify photos of the querying user and thenthe likers of those photos can be identified. Next, the users vertical164 could be searched to identify which of the likers, if any, live inChina. In this way, an inverse operator may be used so that the searchof the first vertical 164 produces better results. This may also allowsocial-networking system 160 to produce better search results and mayimprove the processing efficiency for generating these results. Althoughthis disclosure describes identifying objects matching a structuredquery a particular manner, this disclosure contemplates identifyingobjects matching a structured query in any suitable manner.

In particular embodiments, the search indices for a vertical 164corresponding to an object-type may comprise an inverted index. Aninverted index for a first object-type may map a query term associatedwith a second object-type to one or more objects of the firstobject-type. As an example and not by way of limitation, an invertedindex in the post vertical 164 may map a query term associated with auser such as (posts_liked_by: <user>) from <user> to a list posts likedby <user>. Similarly, the inverted index may map a query term associatedwith a user such as (posts_commented_by: <user>) from <user> to a listof posts commented by <user>. As another example and not by way oflimitation, an inverted index in the photo vertical 164 may map a queryterm associated with a user such as (photos_liked_by: <user>) from<user> to a list of photos liked by <user>. Similarly, the invertedindex may map a query term associated with a user (photos_of: <user>)from <user> to a list of photos that <user> is tagged in. In particularembodiments, an inverted index for a vertical 164 corresponding to anobject-type may map a query term associated with the object-type to oneor more objects of the object-type. As an example and not by way oflimitation, an inverted index in the user vertical 164 may map a queryterm associated with a user such as (friends: <user>) from <user> to alist of friends (i.e., of user object-type) of <user>. In particularembodiments, an inverted index may map one to many for a query term. Asan example and not by way of limitation, an inverted index of the photovertical 164 may map a user to many photos (e.g., more than 100 photos)that the user is tagged in. Although this disclosure describes searchingverticals 164 in a particular manner, this disclosure contemplatessearching verticals in any suitable manner.

In particular embodiments, the search indices for a vertical 164corresponding to an object-type may comprise a forward index. A forwardindex for a first object-type may map a query term associated with thefirst object-type to one or more objects of a second object-type. As anexample and not by way of limitation, a forward index in the postvertical 164 may map a query term associated with a post such as(likers_of: <post>) from <post> to a list of users who like <post>.Similarly, the forward index may map a query term associated with a postsuch as (author_of: <post>) from <post> to a user who is the author of<post>. As another example and not by way of limitation, a forward indexin the photo vertical 164 may map a query term associated with a photosuch as (tagged_in: <photo>) from <photo> to a list of users who aretagged in <photo>. Similarly, the forward index may map a query termassociated with a photo (commenters_of: <photo>) from <photo> to a listof users who comment on <photo>. In particular embodiments, a forwardindex may comprise a one-to-one mapping for a query term. As an exampleand not by way of limitation, a forward index of the photo vertical 164may map a photo to an owner of the photo (e.g., the user who uploadedthe photo to social-networking system 160). In particular embodiments, aforward index may comprise a one-to-few mapping for a query term. As anexample and not by way of limitation, a forward index in the photovertical 164 may map a photo to a few users (e.g., less than 10 users)who are tagged in the photo. Although this disclosure describessearching verticals 164 in a particular manner, this disclosurecontemplates searching verticals in any suitable manner.

In particular embodiments, after parsing a structured query to identifya plurality of query constraints, social-networking system 160 mayidentify an inverse constraint associated with one of the queryconstraints. An inverse constraint essentially reverses the order thatverticals 164 are searched when executing a structured query. If aparticular query constraint requests search results of a firstobject-type having a particular connection to a second object-type, itscorresponding inverse constraint may request search results of thesecond object-type have that connection with the first object-type.Using inverse constraints may be particular useful with nested querieswhen the inner query constraint produces too many results, reducing thelikelihood that any of them will satisfy the outer query constraint. Ifthe query constraint is for a particular object-type, the inverseconstraint may be for a different object-type, or the same object-type.In particular embodiments, the query constraint may be for a firstobject-type corresponding to one or more nodes of a first node-type thatare each connected by one of the selected edges referenced in thestructured query to one or more nodes of a second node-type, and theinverse constraint may be for a second object-type corresponding tocorresponding to one or more nodes of the second node-type that areconnected by the one of the selected edges referenced in the structuredquery to one or more nodes of the first node-type. As an example and notby way of limitation, if the first constraint is for (posts_liked_by:<user>), this query constraint will search for concept nodes 204corresponding to posts objects that are connected by like-type edges 206to a particular user node 202 (or type of user node 202). The inverseconstraint for the first constraint may be, for example, (likers_of:<posts>), which will search for user nodes 202 that are connected bylike-type edges 206 to particular concept nodes 204 (or types of conceptnodes 204) corresponding to particular posts. In other words, instead ofsearching for photos liked by users by using a “liked_by” operator, theinverse constraint will search for users who like photos by using a“likers_of” operator. In particular embodiments, both the queryconstraint and its inverse constraint may be for the same object-type.As another example and not by way of limitation, if the first constraintis for (followers_of: <user>), this query constraint will search for oneor more first users who subscribe or follow a second user. The inverseconstraint for the first constraint may be, for example,(users_followed_by: <user>), which will search for one or more secondusers followed by a first user (or followed by a first type of user).Although this disclosure describes identifying particular inverseconstraints in a particular manner, this disclosure contemplatesidentifying any suitable inverse constraints in any suitable manner.

In particular embodiments, social-networking system 160 may generate aquery command based on a structured query that includes an inverseconstraint. Where the parsing of a structured query identifies a firstquery constraint and one or more second query constraints,social-networking system 160 may identify an inverse constraint for thefirst query constraint and then generate a query command comprising theinverse constraint and the one or more second query constraints. Inparticular embodiments, social-networking system 160, generating a querycommand that includes an inverse constraint may comprise generating aquery command that searches a forward index instead of an invertedindex. As an example and not by way of limitation, if the first queryconstraint is (posts_authored_by: <user>), this query constraint maysearch a post vertical 164 using an inverse index that maps from <user>to a list of posts authored by <user>. Social-networking system 160 maythen generate a query command using an inverse constraint of(posts_authored_by: <user>), which may be, for example, (authors_of:<post>), which may search a users index 164 using a forward index thatmaps from <posts> to a lists of users that authored the <posts>. Inparticular embodiments, the first query constraint may itself be anested query having an inner constraint and an outer constraint. In thiscase, the generated query command may comprise an intersect of the firstinverse constraint and the inner constraint. As an example and not byway of limitation, in response to the structured query “Photos of meliked by people in China”, social-networking system 160 could parse thestructured query to generate a query command such as, for example:intersect(photos_of: <me>, photos_liked_by: (users_from: <China>)).However, executing this query command may produce an inadequate numberof search results since the inner constraint (users_from:<China>) mayidentify a large number of user nodes 202 that do not satisfy the outerconstraint (photos_liked_by:<users>). Thus, social-networking system 160may then generate a query command using an inverse constraint, such as,for example, (intersect(photos_of: <me>, photos_liked_by:(intersect(likers_of(photos_of: <me>), users_from: <China>)))). In thisexample, based on the “liked_by” operator from the outer constraint,social-networking system 160 has modified the query command to includethe inverse “likers_of” operator in the inner constraint, andintersected this with the inner query constraint (users_from:<China>).This will reverse the order in which object-types are searched inverticals 164, such that instead of searching for photos liked by usersin China, to instead search for users who are “likers_of” photos of thequerying user and to intersect those results with a search for users inChina. In particular embodiments, a query command generated using aninverse constraint also be generated using query hinting as describedpreviously, for example, by incorporating WAND and SOR operators, suchthat the query command requires a first number of identified nodes tomatch the inner constraint, or match the inner or outer constraint, anda second number of identified nodes to match both constraints or justthe outer constraint, or any combination thereof. The first and secondnumbers may be, for example, a real number, a percentage, or a fraction.Although this disclosure describes generating particular query commandsin a particular manner, this disclosure contemplates generating anysuitable query commands in any suitable manner.

In particular embodiments, in response to a query command comprising aninverse constraint, social-networking system 160 may identify a firstset of nodes matching the inverse constraint. As previously described,social-networking system 160 may also identify one or more second setsof nodes matching one or more additional query constraints,respectively, of the query command. Matching nodes may be identified inany suitable manner, such as, for example, by referencing search indicesas discussed previously. In particular embodiments, social-networkingsystem 160 may identify one or more nodes of the plurality of one ormore nodes of the plurality of nodes that is connected by one or moreselected edges referenced in the structured query to one or more of thenodes in the first set of nodes. As an example and not by way oflimitation, in response to the structured query “Photos of me liked bypeople in China”, social-networking system 160 may generate a querycommand using an inverse constraint, such as, for example(intersect(photos_of: <me>, photos_liked_by:(intersect(likers_of(photos_of: <me>), users_from: <China>)))). Here,the references in the structured query to “me” and “China” refer toparticular social-graph elements, i.e., a user node 202 corresponding tothe querying user and a concept node 204 corresponding to the location“China”. Similarly, the references to “photos of me” and “liked by”refer to particular edge-types connecting the referenced nodes to thedesired search results. In this case, the query constraint(photos_liked_by: (intersect(likers_of(photos_of: <me>), users_from:<China>))) is itself a nested query, where the inner constraint requestsusers who are “likers_of” photos of the querying user and users who arefrom China. When searching the users vertical 164 to identify matchinguser nodes 202 for the constraint (likers_of(photos_of: <me>)),social-networking system 160 may be able to identify a relatively smallset of nodes, since the number of users who have liked photos of thequerying user is likely a relatively small number (e.g., tens tohundreds of users). Next, social-networking system 160 may search theusers vertical 164 to identify matching user nodes 202 for theconstraint (users_from: <China>). Note that the constraint (users_from:<China>) could produce thousands or millions of results, most of whichwould likely not satisfy the query command. However, by intersectingthis with the objects identified by the inverse constraint, a morereasonably sized set of objects is identified corresponding to usersfrom China who like photos of the querying user. Once this innerconstraint is resolved, the set of identified users may be used toresolve the outer constraint, which is to identify photos liked by usersidentified by the inner constraint. This set of photos may then beintersected with the results of the constraint (photos_of: <me>), sothat a set of photo of the querying user liked by users from China isidentified. Although this disclosure describes identifying particularsocial-graph elements as matching particular inverse constraints in aparticular manner, this disclosure contemplates identifying any suitablesocial-graph elements as matching any suitable inverse constraints inany suitable manner.

In particular embodiments, social-networking system 160 may generate oneor more search results based on a first set of nodes identified asmatching the inverse query constraint and one or more second sets ofnodes matching one or more query constraints, respectively. Each searchresult may correspond to a node of the plurality of nodes. The nodesidentified as matching the query command may be scored (and possiblyranked), and then one or more (e.g., a threshold number) may begenerated as search result to display to the user. The search resultsmay be presented and sent to the querying user as a search-results page,where the generated search results are displayed. As an example and notby way of limitation, in response to the structured query “Photos of meliked by people in China”, as illustrated in FIG. 5D, social-networkingsystem 160 may identify a first set of nodes matching the inverseconstraint. In this example, the inner constraint (as modified by theinverse constraint) requests users from China who are also likers ofphotos of the querying user. Next, social-networking system 160 mayidentify a second set of nodes matching the outer query constraint. Inthis example, the outer constraint requests photos of the querying userliked by one of the users in the first set. One or more search resultsmay then be generated based on the nodes identified in the second set ofnodes. The generated search results may then be sent and displayed tothe querying user as part of a search-results page corresponding to thestructured query “Photos of me liked by people in China”. Thesearch-results page may display the search results, for example, asthumbnails of the photos corresponding to the nodes identified in thesecond set. In particular embodiments, social-networking system 160 maygenerate a search result for each node identified in both the first setof nodes and the second sets of nodes. In particular embodiments,social-networking system 160, each search result generated bysocial-networking system 160 may correspond to a nodes of the first setof nodes that is connected by one or more selected edges referenced inthe structured query to one or more nodes in the second set of nodes (orvice versa). Although this disclosure describes generating particularsearch results in a particular manner, this disclosure contemplatesgenerating any suitable search results in any suitable manner.

In particular embodiments, social-networking system 160 may generate aquery command comprising an inverse constraint when an initial querycommand generates below a threshold number of search result. Whenparsing a nested search query, the typical processing of the query mayproduce an inadequate number of search results. This may happen, forexample, because the inner query constraint produces too many results,reducing the likelihood that any of them will satisfy the outer queryconstraint, and thus few or no search results may be generated. Inverseconstraints may be used in particular scenarios where the originalparsing of a structured query generates a query command that produces aninadequate number of search results. In particular embodiments, inverseconstraints may be used when particular query constraints are identifiedduring parsing of a structured query. Particular query constraints mayhave already been identified as being suitable for substitution using aninverse constraint. In other words, particular query constraints may beflagged as being likely to identify too many objects, so that an inverseconstraint is used in its place. As an example and not by way oflimitation, social-networking system 160 may store (e.g., at aggregator320) a list of query constraints where the set generated by the queryconstraint is likely to be large (e.g., (users_from:<country>), or(likers_of:<page>) for pages having large numbers of likers). When aquery constraint on the list is identified during parsing of a query,social-networking system 160 may then automatically generate a querycommand using an inverse constraint of the listed constraint. Inparticular embodiments, inverse constraints may be used when queryhinting is used to parse nested search queries, such as, for example,when the inner query constraint identifies a large number of objectsthat do not satisfy the outer query constraint. Inverse constraints maybe particular useful in scenarios where the initial parsing of astructured query produces a query command that has an inner constraintthat requests a large number of objects that do not satisfy the outerconstraint. As an example and not by way of limitation,social-networking system 160 may determine a number of nodes satisfyinga first query constraint. If the number of nodes is greater than athreshold number of nodes, then social-networking system 160 maygenerate the query command with the first inverse constraint. Else,social-networking system 160 may generate the query command with thefirst query constraint. In other words, if the original parsing of thestructured query produces a query command that identifies too manyobjects, then an inverse constraint may be used instead to narrow thenumber of results generated. As another example and not by way oflimitation, social-networking system 160 may generate a preliminaryquery command based on the structured query. This preliminary querycommand may include the first query constraint and the one or moresecond query constraints. In this scenario, the preliminary querycommand may be considered the default or normal parsing of thestructured query. Social-networking system 160 may then generate a firstset of search results based on the preliminary query command. If thefirst set of search results is less than a threshold number of searchresults, then social-networking system 160 may generate the querycommand with the first inverse constraint and then generate a second setof search results based on the query command with the first inverseconstraint (for example, by identifying new sets of nodes matching theinverse constraint and the outer constraints). In other words, if theoriginal parsing of the structured query generates too few searchresults, then an inverse constraint may be used to improve the searchresults. Although this disclosure describes generating particular querycommands in a particular manner, this disclosure contemplates generatingany suitable query commands in any suitable manner.

FIG. 7 illustrates an example method 700 for parsing search queriesusing inverse operators. The method may begin at step 710, wheresocial-networking system 160 may access a social graph 200 comprising aplurality of nodes (e.g., user nodes 202 or concept nodes 204) and aplurality of edges 206 connecting the nodes. Each edge between two nodesmay represent a single degree of separation between them. The nodes maycomprise a first node (e.g., a first user node 202) corresponding to afirst user associated with the online social network. The nodes may alsocomprise a plurality of second nodes that each correspond to a conceptor second user associate with the online social network. At step 720,social-networking system 160 may receive from the first user astructured query comprising references to one or more selected nodesfrom the plurality of nodes and one or more selected edges from theplurality of edges. At step 730, social-networking system 160 may parsethe structured query to identify a first query constraint and one ormore second query constraints. At step 740, social-networking system 160may identify a first inverse constraint associated with the first queryconstraints. At step 750, social-networking system 160 may generate aquery command based on the structured query. The query command maycomprise the first inverse constraint and the one or more second queryconstraints. The query command may also comprise the first queryconstraint. At step 760, social-networking system 160 may generate oneor more search results corresponding to the query command. Each searchresult may correspond to a node of the plurality of nodes. Particularembodiments may repeat one or more steps of the method of FIG. 7, whereappropriate. Although this disclosure describes and illustratesparticular steps of the method of FIG. 7 as occurring in a particularorder, this disclosure contemplates any suitable steps of the method ofFIG. 7 occurring in any suitable order. Moreover, although thisdisclosure describes and illustrates particular components, devices, orsystems carrying out particular steps of the method of FIG. 7, thisdisclosure contemplates any suitable combination of any suitablecomponents, devices, or systems carrying out any suitable steps of themethod of FIG. 7.

Generating Search Results Based on Intent

In particular embodiments, in response to a structured query receivedfrom a querying user, social-networking system 160 may generate one ormore search results, where the search results correspond to thestructured query. Social-networking system 160 may identify objects(e.g., users, photos, profile pages (or content of profile pages), etc.)that satisfy or otherwise match the structured query. A search resultcorresponding to each identified object may then be generated. As anexample and not by way of limitation, in response to the structuredquery “Photos of Matt and Stephanie”, social-networking system 160 mayidentify a photo where the user's “Matt” and “Stephanie” are both taggedin the photo. A search result corresponding to this photo may then begenerated and sent to the user. In particular embodiments, each searchresult may be associated with one or more objects, where each queryconstraint of the structured query is satisfied by one or more of theobjects associated with that particular search result. As an example andnot by way of limitation, continuing with the prior example, in responseto the structured query “Photos of Matt and Stephanie”,social-networking system 160 may parse the query to generate the querycommand (intersect(photos_of:<Matt>), (photos_of:<Stephanie>)), whichcould be executed to generate a search result corresponding to a photowhere the user's “Matt” and “Stephanie” (who were both referenced in thestructured query) are both tagged in the photo (i.e., their user nodes202 are connected by tagged-in-type edges 206 to the concept node 204corresponding to the photo). In other words, the constraints for(photos_of:<Matt>) and (photos_of:<Stephanie>) are both satisfied by thephoto because it is connected to the user nodes 202 for the user's“Matt” and “Stephanie”. Although this disclosure describes generatingsearch results in a particular manner, this disclosure contemplatesgenerating search results in any suitable manner.

In particular embodiments, social-networking system 160 may generatesearch results based on a search intent of the querying user. The searchresults (e.g., the identified nodes or their corresponding profilepages) may be scored (or ranked) and presented to the user according totheir relative degrees of relevance to the search query, as determinedby the particular search algorithm used to generate the search results.The search results may also be scored and presented to the useraccording to their relative degree of relevance to the user. Inparticular embodiments, the search algorithm used to score the searchresults may be varied based on the search intent of the querying user.Search intent refers to the intent of the querying user with respect tothe type of search query and/or the type of search mode that the user isin. In response to a search query, social-networking system 160 maydetermine one or more search intents for the search query. Search intentmay be determined in a variety of ways, such as, for example, based onsocial-graph elements referenced in the search query, terms within thesearch query, user information associate with the querying user, searchhistory of the querying user, pattern detection, other suitableinformation related to the query or the user, or any combinationthereof. The search algorithm used to generate search results may bemodified based on these search intents, such that the way search resultsare ranked in response to one query may be different from the way searchresults are ranked in response to another query. As an example and notby way of limitation, if the querying user is interested in identifyingother users that the querying user might be interested in dating, thesearch results generated in response to a search query with a datingintent may rank the results such that users who indicate they are“single” are ranked higher than users who indicate they are “in arelationship”. Similarly, if the querying user is interested inidentifying users to network with in order to find a job, the searchresult generated in response to a search query with a networking intentmay be ranked so that users who work at companies in the same geographicarea as the querying user are ranked higher than users who work atgeographically distant companies. In particular embodiments, the searchresults may scored or ranked by a particular scoring/ranking algorithmimplemented by the search engine. As an example and not by way oflimitation, search results that are more relevant to the search query orto the user may be scored higher than the resources that are lessrelevant. The way relevance is determined may be modified based on thesearch intent identified by social-networking system 160. In particularembodiments, social-networking system 160 may rank the one or moresearch results. Search results may be ranked, for example, based on thescore determined for the search result. The most relevant result (e.g.,highest/best scoring) may be ranked highest, with the remaining resultshaving lower ranks commensurate with their score/relevance, such thatthe least relevant result is ranked lowest. Although this disclosuredescribes ranking search results based on search intent in a particularmanner, this disclosure contemplates ranking search results based onsearch intent in any suitable manner.

In particular embodiments, social-networking system 160 may determineone or more search intents based on one or more of the selected nodes orselected edges referenced in a structured query. Particular social-graphelements may correspond to particular search intents. In particularembodiments, social-networking system 160 may determine the probabilitythat a particular social-graph element corresponds to a particularsearch intent based social-graph information. As an example and not byway of limitation, when determining a probability, p, that a particularsearch intent is associated with a particular query, the calculation ofthe probability may also factor in social-graph information. Thus, theprobability of corresponding to a particular search intent, I, given aparticular social-graph element, X, and query, q, may be calculated asp=(I|X,q). In particular embodiments, social-networking system 160 mayidentify one or more search intents that correspond to one or more ofthe nodes or one or more of the edges referenced in the structuredquery. Each search intent may correspond to one or more social-graphelements. Similarly, a particular social-graph element may correspond toone or more search intents. As an example and not by way of limitation,for the structured query “Single women in Palo Alto”, social-networkingsystem 160 may determine that the single-type edge 206 referenced in thestructured query may correspond to an intent for dating, indicating thatthe querying user is interested in finding users for dating orsocializing purposes. Similarly, the female-gender-type edge 206referenced in the structured query may also corresponding to an intentfor dating. In other words, because the querying user submitted astructured query referencing the social-graph elements corresponding to“single” and/or “women”, social-networking system 160 may be able todetermine that the querying user is attempting to find objects fordating purposes, and may then be able to subsequently score/rank searchresult appropriately based on this determined intent. As another exampleand not by way of limitation, for the structured query “People who workas software engineers in Palo Alto”, social-networking system 160 maydetermine that the work-at-type edge 206 referenced in the structuredquery may correspond to an intent for networking, indicating that thequerying user is interested in finding user for networking, recruiting,or employment purposes. Although this disclosure describes particulartypes of search intents, this disclosure contemplates any suitable typesof search intents. In particular embodiments, social-networking system160 may identify one or more search intents by referencing apattern-detection model. As an example and not by way of limitation,social-networking system 160 may access a pattern-detection model thatindexes particular social-graph elements that correspond to particularsearch intents. The index may indicate, for example, that particularnodes or node-types, or particular edges or edge-types, alone or incombination, correspond to particular search intents. Social-networkingsystem 160 may then determine whether any of the nodes or edgesreferenced in the structured query match the nodes or edges indexed inthe pattern-detection model. For each matching node or edge found in theindex, social-networking system 160 may identify the search intentindexed in the pattern-detection model as corresponding to the matchingnode or matching edge referenced in the structured query. Although thisdisclosure describes determining particular search intents in aparticular manner, this disclosure contemplates determining any suitablesearch intents in any suitable manner.

In particular embodiments, social-networking system 160 may determineone or more search intents based on user information from a user-profilepage associated with the querying user. The querying user may beassociated with a particular user node 202 of the social graph 200, andmay also be associated with a particular user-profile page. Particularuser information may correspond to particular search intents. As anexample and not by way of limitation, where a querying user hasindicated on his user-profile page that he is “single” in arelationship-status field (i.e. not in a relationship),social-networking system 160 may determine that this user-profileinformation corresponds to an intent for dating. Social-networkingsystem 160 may then determine that particular structured queries fromthis querying user are more likely to be associated with a dating searchintent. As another example and not by way of limitation, where aquerying user has indicated on her user-profile page that she is“unemployed” in a work-history field, social-networking system 160 maydetermine that this user-profile information corresponds to an intentfor networking. Social-networking system 160 may then determine thatparticular structured queries from this querying user are more likely tobe associated with a networking intent. Although this disclosuredescribes determining search intents based on particular userinformation in a particular manner, this disclosure contemplatesdetermining search intents based on any suitable user information in anysuitable manner.

In particular embodiments, social-networking system 160 may determineone or more search intents based on one or more of query constraints ofthe query command generated in response to the structured query. Inresponse to receiving a structure query from the querying user,social-networking system 160 may generate a query command based on thestructured query, where the query command may comprise one or more queryconstraints. Particular query constraints may correspond to particularsearch intents. As an example and not by way of limitation, for thestructured query “Single women in Palo Alto”, social-networking system160 may generate a query command such as, for example,(intersect(user_gender:<female>, user_location:<Palo Alto>,user_relationship_status:<single>)). Social-networking system 160 maythen determine that the query constraint for (user_gender:<female>)corresponds to an intent for dating. Although this disclosure describesdetermining search intents based on particular query constraints in aparticular manner, this disclosure contemplates determining searchintents based on any suitable query constraints in any suitable manner.

In particular embodiments, social-networking system 160 may determineone or more search intents based a search history associated with thequerying user. Search intents previously determined for the queryinguser may be more likely to match the search intent of the queryinguser's current search query. As an example and not by way of limitation,if querying user has previously run search queries thatsocial-networking system 160 has determined correspond to a datingintent, when determining the probability that subsequent search queriescorresponds to a particular search intent, social-networking system 160may determine that the dating intent has a relatively higher probabilityof corresponding to the subsequent search query because the queryinguser has previously run search queries having that intent. As anotherexample and not by way of limitation, if querying user has never runsearch queries that social-networking system 160 has determinedcorrespond to a networking intent, when determining the probability thatsubsequent search queries corresponds to a particular search intent,social-networking system 160 may determine that the networking intenthas a relatively lower probability of corresponding to the subsequentsearch query because the querying user has never run search querieshaving that intent. Although this disclosure describes determiningsearch intents based on particular search history information in aparticular manner, this disclosure contemplates determining searchintents based on any suitable search history information in any suitablemanner.

In particular embodiments, social-networking system 160 may determineone or more search intents based on one or more n-grams from thestructured query. The n-gram may be any contiguous sequence of n itemsfrom the structured query, which may include character strings orsocial-graph references. Particular n-grams may correspond to particularsearch intents. Although this disclosure describes determining searchintents based on particular query terms in a particular manner, thisdisclosure contemplates determining search intents based on any suitablequery terms in any suitable manner.

In particular embodiments, social-networking system 160 may score thegenerated search results based on search intent. The search intent mayindicate that the search results should be scored based on one or morefactors, such as, for example, search counts or ratios, social-graphinformation, social-graph affinity, search history, other suitablefactors, or any combination thereof. Search results may also be scoredbased on advertising sponsorship. Although this disclosure describesscoring search results in a particular manner, this disclosurecontemplates scoring search results in any suitable manner.

In particular embodiments, social-networking system 160 may score thesearch results based on one or more search intents. Social-networkingsystem 160 may score the search results using one or more scoringalgorithms, where the search results may be scored based on theirrelevance to the search query. In some cases, a user may submit a searchrequest for particular object-types, such as photos or users matchingcertain query constraints, but may desire more diversity in searchresults than simply the top N objects determined by a static ranking.Instead, the querying user may desire to see search results that reflectthe user's search intent. The determination of relevance, and thus thescoring of the search results, may be modified or customized by thedetermined search intent for the query. Particular scoring algorithmsmay be used for particular search intents, and particular factors of ascoring algorithm may be weighted more or less for particular searchintents. As an example and not by way of limitation, continuing with aprior example, in response to the structured query “People who work assoftware engineers in Palo Alto”, social-networking system 160 maydetermine that one of the search intents of the query is for networking.When scoring the identified user nodes 202 matching this query,social-networking system 160 may typically score based on social-graphaffinity and score first-degree connections of the querying user betterthan more distant connections. However, if a user is querying fornetworking purposes, the user may not care about thedegree-of-connection between the querying user and the identified usernodes 202. More useful for networking purposes may be to identify userswho, for example, have more experience working as a software engineer,or users who are connected to other users who are also softwareengineers (particularly other software engineers who also live in PaloAlto). Thus, when scoring the search results based on the networkingsearch intent, social-networking system 160 may use a scoring algorithmthat gives less weight to the user's distance in the social graph 200and more weight to social-graph information related to the user's workhistory and relevant work-related connections. Although this disclosuredescribes scoring search results in a particular manner, this disclosurecontemplates scoring search results in any suitable manner.

In particular embodiments, scoring the search results based on searchintent may comprise scoring the search results based on a count or ratioof the objects of the search result that satisfy the query constraintsof the search query. Based on the identified search intents for thesearch query, the count, the ratio, or any combination thereof may beused as a factor when scoring the search results. For particular queryconstraints, the constraint may be satisfied multiple times by aparticular object. Although this disclosure describes scoring searchresults based on search intent in a particular manner, this disclosurecontemplates scoring search results based on search intent in anysuitable manner.

In particular embodiments, social-networking system 160 may score thesearch results based on a count of the objects of the search result thatsatisfy the query constraints of the search query. In certain cases, aparticular object matching a query constraint may in fact have multipleattributes that satisfy the constraint. As an example and not by way oflimitation, locations may have multiple check-ins by users, photos mayhave multiple users tagged in them, groups may have multiple users whoare members, etc. In these types of cases, the count of how many times aparticular query constraint is being satisfied may be considered whenranking the search results. As an example and not by way of limitation,in response to a structured query for “Photos of my friends”,social-networking system 160 may generate the query command(photos_of(users:<friends>)), and may determine that a search intent ofthis query is to view group photos the user's friends. However, thisquery command may be satisfied, for example, by a photo that has onlyone friend of the querying user tagged in it, or may be satisfiedmultiple times by a photo that has multiple friends tagged in it.Consequently, when scoring identified concept nodes 204 corresponding tophotos with the user's friends tagged in the photo, social-networkingsystem 160 may score photos better based on the number of the user'sfriends that are tagged in the photo. Thus, a photo that only has onefriend tagged in it (such as, for example, a user's profile picture),may be scored worse than a photo that has several of the user's friendstagged in it. As another example and not by way of limitation, inresponse to a structured query for “Photos of single women”,social-networking system 160 may determine that a search intent of thisquery is to view individual photos of single women (i.e., photos wherethe only user in the photo is the single woman). However, this querycommand may be satisfied, for example, by a group photo of single women,or a photo having just one user tagged in it who is a single woman.Consequently, when scoring identified concept nodes 204 corresponding tophotos with single women tagged in them, social-networking system 160may score photos of single women standing alone better than photos of agroup of single women (or photos of a single woman with one or moreother users who are not single women). Furthermore, profile pictures ofsingle women may be scored better than non-profile pictures of singlewomen. Although this disclosure describes scoring search results basedon search result counts in a particular manner, this disclosurecontemplates scoring search results based on search result counts in anysuitable manner.

In particular embodiments, social-networking system 160 may score thesearch results based on a ratio of the objects of the search result thatsatisfy the query constraints of the search query. As describedpreviously, a particular object matching a query constraint may havemultiple attributes that satisfy the constraint. But the same object mayalso have multiple attributes that do not satisfy the constraint. Inthese types of cases, the count of how many times a particular queryconstraint is being satisfied compared to how many time it is not beingsatisfied (i.e., a ratio) may be considered when ranking the searchresults. As an example and not by way of limitation, in response to astructured query for “Photos of my family”, social-networking system 160may generate the query command (photos_of(users:<family>)), and maydetermine that a search intent of this query is to view group photosshowing the user's family and no one else. In other words, an idealmatch would be a photo where the ratio of people tagged in the photo whosatisfy the query constraint is as close to 1 as possible (i.e., onlymembers of the user's family are tagged in the photo and no other usersare tagged in the photos). However, this query command may be satisfied,for example, by a photo that has only one member of the user's family init along with several other users, or a photo that has all members ofthe user's family and several other people tagged in it. Consequently,when scoring identified concept nodes 204 corresponding to photos withthe user's family members tagged in the photo, social-networking system160 may score photos better based on the ratio of users tagged in thephoto that belong to the user's family (i.e., the concept node 204corresponding to the photo is connected by tagged-in-type edges 206 toone or more user nodes 202 corresponding to users connected byfamily-type edges 206 to the querying user). Thus, a photo showing fourof the user's family members posing with three other non-family membersmay be scored worse than a photo that only shows three of the user'sfamily members (thus, a lower count) but where no other users are taggedin the photo (thus, a higher ratio). Although this disclosure describesscoring search results based on search result rations in a particularmanner, this disclosure contemplates scoring search results based onsearch result rations in any suitable manner.

In particular embodiments, social-networking system may score the searchresults based on a count of objects of the search result that satisfymultiple query constraints of the search query. Where the search queryhas a plurality of query constraints, search results that include asingle object that satisfies multiple query constraints may beundesirable. In certain cases, a particular object matching a querycommand with multiple query constraints may satisfy a plurality of thequery constraints based on one or more attributes. In these types ofcases, the count of how many objects/attributes are being used tosatisfy these query constraints may be considered when ranking thesearch results. For certain queries, it is desirable to use differentnodes or edges to satisfy each query constraint of a query commandhaving a plurality of constrains. As an example and not by way oflimitation, in response to the structured query “Restaurants liked byMark and men”, social-networking system 160 may parse the structuredquery as a query command such as, for example, (intersect(locations:<restaurants>), (intersect(locations(liked_by: <Mark>),locations(liked_by(user_gender: <male>))), and may determine that asearch intent of this query is to identify restaurants liked by the user“Mark” and at least one other person who is also male. In this case,assume the user “Mark” is also a male. Social-networking system 160 mayidentify a first set of objects matching the first query constraint,which will be locations that are restaurants (i.e., concept nodes 204corresponding to locations that are connected by location_type edges 206to a concept node 204 corresponding to “Restaurants”). Next,social-networking system 160 may intersect these results with a secondset of objects identified as matching the second query constraint (whichitself has multiple constraints), which will be locations liked by boththe user “Mark” and by male users. However, since the user “Mark” isalso male, locations liked by “Mark” may also be identified in thissecond set of objects. In this case, since a restaurant where only theuser “Mark” likes it may be in both the first and second sets ofobjects, it is possible for social-networking system 160 to generate asearch result corresponding to a location where the only user who likesit is the user “Mark” (or “Mark” and only female users). But thequerying user is unlikely to want to view search results correspondingto only restaurants liked by “Mark” (in which case, the querying usercould have simply searched for “Restaurants liked by Mark”). The user ismore likely trying to find restaurants liked by at least twousers—“Mark” and at least one other user who is male. Thus,social-networking system 160 may count whether one or two like-typeedges 206 are being used to satisfy the query command (i.e., whether alike-type edge 206 connected to just “Mark” is being used, or if atleast two different like-type edges 206 are being used: one from “Mark”and one from another user”). Thus, a restaurant where only a singlelike-type edge 206 is being used to satisfy both query constraints maybe scored worse than a restaurant where two different like-type edges206 are being used to satisfy the constraints. Although this disclosuredescribes scoring search results based on query constraints intent in aparticular manner, this disclosure contemplates scoring search resultsbased on query constraints in any suitable manner.

In particular embodiments, social-networking system 160 may score thesearch results based on a social-graph affinity associated with thequerying user (or the user node 202 of the querying user).Social-networking system 160 may determine the social-graph affinity(which may be referred to herein as “affinity”) of various social-graphentities for each other. Affinity may represent the strength of arelationship or level of interest between particular objects associatedwith the online social network, such as users, concepts, content,actions, advertisements, other objects associated with the online socialnetwork, or any suitable combination thereof. In particular embodiments,social-networking system 160 may measure or quantify social-graphaffinity using an affinity coefficient (which may be referred to hereinas “coefficient”). The coefficient may represent or quantify thestrength of a relationship between particular objects associated withthe online social network. The coefficient may also represent aprobability or function that measures a predicted probability that auser will perform a particular action based on the user's interest inthe action. In particular embodiments, social-graph affinity may be usedas a factor when scoring search results. As an example and not by way oflimitation, in response to the structured query “Photos of my friends”,social-networking system 160 may generate the query command(photos_of(users:<friends>)), and may determine that the search intentof this query is to view group photos showing the user's friends. Whenscoring identified concept nodes 204 corresponding to photos with theuser's friends tagged in the photo, social-networking system 160 mayscore photos better based on the querying user's respective social-graphaffinity (e.g., as measured by a affinity coefficient) of the user'stagged in the photo with respect to the querying user. Furthermore,photos showing more of the querying user's friends may be tagged higherthan photos showing fewer of the user's friends, since having morefriends tagged in the photo may increase the querying user's affinitywith respect to that particular photo. Although this disclosuredescribes scoring search results based on affinity in a particularmanner, this disclosure contemplates scoring search results based onaffinity in any suitable manner. Furthermore, in connection withsocial-graph affinity and affinity coefficients, particular embodimentsmay utilize one or more systems, components, elements, functions,methods, operations, or steps disclosed in U.S. patent application Ser.No. 11/503,093, filed 11 Aug. 2006, U.S. patent application Ser. No.12/977,027, filed 22 Dec. 2010, U.S. patent application Ser. No.12/978,265, filed 23 Dec. 2010, and U.S. patent application Ser. No.13/632,869, filed 1 Oct. 2012, each of which is incorporated byreference.

In particular embodiments, scoring the search results based on searchintent may comprise scoring the search results based on social-graphinformation, such as, for example, the degree of separation in thesocial graph 200, node-type and edge-type information, social-graphaffinity, other suitable social-graph information, or any combinationthereof. As an example and not by way of limitation, in response to thestructured query “Single women in Palo Alto”, social-networking system160 may determine that one of the search intents of the query is fordating. When scoring the identified user nodes 202 matching this query,social-networking system 160 may score based on social-graph affinityand score first-degree connections of the querying user better than moredistant connections. However, if a user is querying for dating purposes,the user may be unlikely to want to view first-degree connections (i.e.,the user's friends). More useful for dating purposes may be to identifysecond-degree connections (i.e., friends-of-friends) who are singlewomen. Thus, when scoring the search results based on the dating searchintent, social-networking system 160 may use a scoring algorithm thatscores second-degree connections better than first-degree connections.As another example and not by way of limitation, continuing with theprior example, when scoring the identified user nodes 202 matching thestructured query “Single women in Palo Alto”, social-networking system160 may score users better based on the number of “likes” the profilepicture of the user has, where users with popular profile pictures(i.e., the concept node 204 corresponding to the profile picture isconnected to many user nodes 202 by like-type edges 206) may beconsidered more attractive candidates for dating. Although thisdisclosure describes scoring search results based on social-graphinformation in a particular manner, this disclosure contemplates scoringsearch results based on social-graph information in any suitable manner.

In particular embodiments, scoring the search results based on searchintent may comprise scoring the search results to exclude conversesearch results. One or more of the search intents identified bysocial-networking system 160 may comprise an intent to exclude conversesearch results. In this case, scoring the search results may comprisedowngrading the score of each search result corresponding to at leastone of the selected nodes referenced in the structured query. In certainscenarios, a querying user is unlikely to want to view a search resultthat corresponds to a node referenced in the structured query thequerying user just transmitted to social-networking system 160,notwithstanding the fact that the referenced node may in fact satisfythe constraints of the query. As an example and not by way oflimitation, in response to the structured query “People in photos ofme”, social-networking system 160 may parse the structured query as aquery command such as, for example, (users_tagged_in(photo_of(<me>)).Social-networking system 160 may then generate search results listingusers of the online social network that are tagged in photos where thequerying user is also tagged. In this case, the querying user isobviously a person that is tagged in photos of the querying user, butthe querying user is unlike to want to view a search resultcorresponding to himself (in fact, because the querying user is taggedin every photo of himself, he may be the best match to this query).Thus, social-networking system 160 may determine that one of the searchintents of the query is to exclude converse results, which are searchresult corresponding nodes referenced in the structured query.Continuing with the prior example, the converse result would be thesearch result corresponding the querying user. Thus, even though thequerying user (or the user node 202 corresponding to the querying user)would be identified by the query command, when scoring the searchresults, the search result corresponding to the querying user could bedowngraded so that it is excluded from the search result that areactually transmitted back to the querying user, or at least scored suchthat it is ranked lower then other results. Although this disclosuredescribes scoring particular search results in a particular manner, thisdisclosure contemplates scoring any suitable search results in anysuitable manner.

In particular embodiments, scoring the search results based on searchintent may comprise scoring the search results to exclude inner searchresults. One or more of the search intents identified bysocial-networking system 160 may comprise an intent to exclude innersearch results. In this case, scoring the search results may comprisedowngrading the score of each search result corresponding to at leastone of the nodes of the first set of nodes identified as matching theinner constraint. In certain scenarios, a querying user is unlikely towant to view a search result that matches both the inner and outer queryconstraints. As an example and not by way of limitation, in response tothe structured query “Friends of Facebook employees”, social-networkingsystem 160 may parse the structured query as a query command such as,for example, (friends_of(users_employed_by(<Facebook>))).Social-networking system 160 may identify a first set of objectsmatching the inner query constraint, which will be users that areFacebook employees (i.e., user nodes 202 connected by employed-by-typeedges 206 to the concept node 204 for the company “Facebook”). Next,social-networking system 160 may identify a second set of objectsmatching the outer query constraint, which will be users who are friendsof the first set of users (i.e., user nodes 202 connected by friend-typeedges 206 to the user nodes 202 in the first set). In this case, manyusers who are friends of Facebook employees (the matches for the outerconstraint) may also be Facebook employees (the matches for the innerconstraint), but the querying user is unlikely to want to view searchresults corresponding to Facebook employees (in which case, the queryinguser could have just searched for “People who are Facebook employees”).The user is more likely trying to identify non-Facebook employees whoare friends with Facebook employees. Thus, social-networking system 160may determine that one of the search intents of the query is to excludeinner search results, which are search result matching to the innerquery constraint. Continuing with the prior example, the inner searchresults would be search results corresponding to Facebook employees.Thus, even though many Facebook employees are friends of other Facebookemployees, the scores for search results corresponding to Facebookemployees may be downgraded so that they are excluded from the searchresults that are actually transmitted back to the querying user, or atleast scored such that they are ranked lower than search resultscorresponding to non-employees of Facebook who are friends of Facebookemployees. Although this disclosure describes scoring particular searchresults in a particular manner, this disclosure contemplates scoring anysuitable search results in any suitable manner.

In particular embodiments, scoring the search results based on searchintent may comprise scoring the search results to exclude duplicatesearch results. One or more of the search intents identified bysocial-networking system 160 may comprise an intent to exclude duplicatesearch results. In this case, scoring the search results may comprisedowngrading the score of each search result corresponding to a node thatmatches both the first query constraint and the second query constraint.In certain scenarios, a querying user is unlikely to want to view asearch result where the same attribute of the object is being used tosatisfy two different constraints in a query command. As an example andnot by way of limitation, in response to the structured query “Photos ofMark with Facebook employees,” social-networking system 160 may parsethe structured query as a query command such as, for example,(intersect(photos_of: <Mark>), photos_of(users_employed_by:<Facebook>)). In this case, assume the user “Mark” is also a Facebookemployee. Social-networking system 160 may identify a first set ofobjects matching the first query constraint, which will be photos of theuser “Mark” (i.e. concept nodes 204 corresponding to photos that areconnected by tagged-in-type edges 206 to the user node 202 correspondingto the user “Mark”). Next, social-networking system 160 may intersectthese results with a second set of objects identified as matching thesecond query constraint (which is a nested constraint), which will bephotos of users that are Facebook employees. However, since the user“Mark” is also a Facebook employee, photos of “Mark” may also beidentified in this second set. In this case, since a photo where onlythe user “Mark” is tagged to be in both the first and second sets ofobjects, it is possible for social-networking system 160 to generate asearch result corresponding a photo where the only user tagged in thephoto is the user “Mark”. But the querying user is unlikely to want toview search results correspond to photos of only “Mark” (in which case,the querying user could have simply searched for “Photos of Mark”). Theuser is more likely trying to identify photos that include at least twousers—“Mark” and at least one other user who is a Facebook employee.Thus, social-networking system 160 may determine that one of the searchintents of the query is to exclude duplicate search results, which aresearch results where the same attribute of the search result is beingused to satisfy two different query constraints. Continuing with theprior example, the first constraint would generate search resultcorresponding to photos Mark (who happens to be a Facebook employee inthis example), and the second constraint would generate search resultcorresponding to photos Facebook employees. In other words, a conceptnode 204 corresponding to particular photo may satisfy both constraintsby simply being connected to a single user node 202 corresponding to theuser “Mark” by a tagged-in-type edge 206 because that user node 202 isconnected by an employed-by-type edge 206 to the concept node for thecompany “Facebook”. Thus, even though the user “Mark” is a Facebookemployee, when scoring the search results, the search resultscorresponding to photos of just “Mark” (or even “Mark” with othernon-employees of Facebook) may be downgraded so they are excluded fromthe search results that are transmitted back to the querying user, or atleast scored such that they are ranked lower than search resultcorresponding to photos of the user “Mark” with at least one other userwho is also a Facebook employee. Although this disclosure describesscoring particular search results in a particular manner, thisdisclosure contemplates scoring any suitable search results in anysuitable manner.

In particular embodiments, social-networking system 160 may send one ormore search results to the querying user. The search results may be sentto the user, for example, in the form of a list of links on thesearch-results webpage, each link being associated with a differentwebpage that contains some of the identified resources or content. Inparticular embodiments, each link in the search results may be in theform of a Uniform Resource Locator (URL) that specifies where thecorresponding webpage is located and the mechanism for retrieving it.Social-networking system 160 may then send the search-results webpage tothe web browser 132 on the user's client system 130. The user may thenclick on the URL links or otherwise select the content from thesearch-results webpage to access the content from social-networkingsystem 160 or from an external system (such as, for example, third-partysystem 170), as appropriate. In particular embodiments, each searchresult may include link to a profile page and a description or summaryof the profile page (or the node corresponding to that page). The searchresults may be presented and sent to the querying user as asearch-results page. When generating the search results,social-networking system 160 may generate one or more snippets for eachsearch result, where the snippets are contextual information about thetarget of the search result (i.e., contextual information about thesocial-graph entity, profile page, or other content corresponding to theparticular search result). In particular embodiments, social-networkingsystem 160 may only send search results having a score/rank over aparticular threshold score/rank. As an example and not by way oflimitation, social-networking system 160 may only send the top tenresults back to the querying user in response to a particular searchquery. Although this disclosure describes sending particular searchresults in a particular manner, this disclosure contemplates sending anysuitable search results in any suitable manner.

In particular embodiments, social-networking system 160 may generate thequery command based on one or more search intents. The structure of aquery command generated by social-networking system 160 may be modifiedbased on these search intents, such that the way a query command isgenerated in response to one structured query may be different from theway a query command is formed in response to another structured query.Similarly, one or more query constraints of a query command may be basedon these search intents. Thus, as an alternative to, or in addition to,scoring/ranking search results based on search intent, the way searchresults are identified by social-networking system 160 when executing aquery command. As an example and not by way of limitation, intents toidentify particular nodes or node-types, identify nodes using queryhinting, identify nodes using inverse operators, exclude converse searchresults, exclude inner search results, exclude duplicate results, othersuitable intents, or any combination thereof may be used when generatinga query command (or a particular query constraint of the query command)in response to a structured query received by social-networking system160. Although this disclosure describes generating query commands basedon particular search intents in a particular manner, this disclosurecontemplates generating query commands based on any suitable searchintents in any suitable manner.

FIG. 8 illustrates an example method 800 for generating search resultsbased on search intent. The method may begin at step 810, wheresocial-networking system 160 may access a social graph 200 comprising aplurality of nodes (e.g., user nodes 202 or concept nodes 204) and aplurality of edges 206 connecting the nodes. Each edge between two nodesmay represent a single degree of separation between them. The nodes maycomprise a first node (e.g., a first user node 202) corresponding to afirst user associated with the online social network. The nodes may alsocomprise a plurality of second nodes that each correspond to a conceptor second user associate with the online social network. At step 820,social-networking system 160 may receive from the first user astructured query comprising references to one or more selected nodesfrom the plurality of nodes and one or more selected edges from theplurality of edges. At step 830, social-networking system 160 maygenerate one or more search results corresponding to the structuredquery. Each search result may correspond to a node of the plurality ofnodes. At step 840, social-networking system 160 may determine one ormore search intents based on one or more of the selected nodes or one ormore of the selected edges referenced in the structured query. At step850, social-networking system 160 may score the search results based onone or more of the search intents. At step 860, social-networking system160 may send one or more of the search results to the first user.Particular embodiments may repeat one or more steps of the method ofFIG. 8, where appropriate. Although this disclosure describes andillustrates particular steps of the method of FIG. 8 as occurring in aparticular order, this disclosure contemplates any suitable steps of themethod of FIG. 8 occurring in any suitable order. Moreover, althoughthis disclosure describes and illustrates particular components,devices, or systems carrying out particular steps of the method of FIG.8, this disclosure contemplates any suitable combination of any suitablecomponents, devices, or systems carrying out any suitable steps of themethod of FIG. 8.

More information on generating search results may be found in U.S.patent application Ser. No. 13/731,939, filed 31 Dec. 2012, which isincorporated by reference.

Advertising

In particular embodiments, an advertisement may be text (which may beHTML-linked), one or more images (which may be HTML-linked), one or morevideos, audio, one or more ADOBE FLASH files, a suitable combination ofthese, or any other suitable advertisement in any suitable digitalformat presented on one or more webpages, in one or more e-mails, or inconnection with search results requested by a user). In addition or asan alternative, an advertisement may be one or more sponsored stories(e.g. a news-feed or ticker item on social-networking system 160). Asponsored story may be a social action by a user (such as “liking” apage, “liking” or commenting on a post on a page, RSVPing to an eventassociated with a page, voting on a question posted on a page, checkingin to a place, using an application or playing a game, or “liking” orsharing a website) that an advertiser promotes by, for example, havingthe social action presented within a pre-determined area of a profilepage of a user or other page, presented with additional informationassociated with the advertiser, bumped up or otherwise highlightedwithin news feeds or tickers of other users, or otherwise promoted. Theadvertiser may pay to have the social action promoted. As an example andnot by way of limitation, advertisements may be included among thesearch results of a search-results page, where sponsored content ispromoted over non-sponsored content. As another example and not by wayof limitation, advertisements may be included among suggested searchquery, where suggested queries that reference the advertiser or itscontent/products may be promoted over non-sponsored queries. Inparticular embodiments, the social-networking system 160 may select anadvertisement to display to a user based on the search intent associatedwith a search query received from the user. Different advertisements (ortypes of advertisements) may be displayed to the user depending on theuser's search intent.

In particular embodiments, an advertisement may be requested for displaywithin social-networking-system webpages, third-party webpages, or otherpages. An advertisement may be displayed in a dedicated portion of apage, such as in a banner area at the top of the page, in a column atthe side of the page, in a GUI of the page, in a pop-up window, in adrop-down menu, in an input field of the page, over the top of contentof the page, or elsewhere with respect to the page. In addition or as analternative, an advertisement may be displayed within an application. Anadvertisement may be displayed within dedicated pages, requiring theuser to interact with or watch the advertisement before the user mayaccess a page or utilize an application. The user may, for example viewthe advertisement through a web browser.

A user may interact with an advertisement in any suitable manner. Theuser may click or otherwise select the advertisement. By selecting theadvertisement, the user may be directed to (or a browser or otherapplication being used by the user) a page associated with theadvertisement. At the page associated with the advertisement, the usermay take additional actions, such as purchasing a product or serviceassociated with the advertisement, receiving information associated withthe advertisement, or subscribing to a newsletter associated with theadvertisement. An advertisement with audio or video may be played byselecting a component of the advertisement (like a “play button”).Alternatively, by selecting the advertisement, social-networking system160 may execute or modify a particular action of the user.

An advertisement may include social-networking-system functionality thata user may interact with. For example, an advertisement may enable auser to “like” or otherwise endorse the advertisement by selecting anicon or link associated with endorsement. As another example, anadvertisement may enable a user to search (e.g., by executing a query)for content related to the advertiser. Similarly, a user may share theadvertisement with another user (e.g. through social-networking system160) or RSVP (e.g. through social-networking system 160) to an eventassociated with the advertisement. In addition or as an alternative, anadvertisement may include social-networking-system context directed tothe user. For example, an advertisement may display information about afriend of the user within social-networking system 160 who has taken anaction associated with the subject matter of the advertisement.

Systems and Methods

FIG. 9 illustrates an example computer system 900. In particularembodiments, one or more computer systems 900 perform one or more stepsof one or more methods described or illustrated herein. In particularembodiments, one or more computer systems 900 provide functionalitydescribed or illustrated herein. In particular embodiments, softwarerunning on one or more computer systems 900 performs one or more stepsof one or more methods described or illustrated herein or providesfunctionality described or illustrated herein. Particular embodimentsinclude one or more portions of one or more computer systems 900.Herein, reference to a computer system may encompass a computing device,and vice versa, where appropriate. Moreover, reference to a computersystem may encompass one or more computer systems, where appropriate.

This disclosure contemplates any suitable number of computer systems900. This disclosure contemplates computer system 900 taking anysuitable physical form. As example and not by way of limitation,computer system 900 may be an embedded computer system, a system-on-chip(SOC), a single-board computer system (SBC) (such as, for example, acomputer-on-module (COM) or system-on-module (SOM)), a desktop computersystem, a laptop or notebook computer system, an interactive kiosk, amainframe, a mesh of computer systems, a mobile telephone, a personaldigital assistant (PDA), a server, a tablet computer system, or acombination of two or more of these. Where appropriate, computer system900 may include one or more computer systems 900; be unitary ordistributed; span multiple locations; span multiple machines; spanmultiple data centers; or reside in a cloud, which may include one ormore cloud components in one or more networks. Where appropriate, one ormore computer systems 900 may perform without substantial spatial ortemporal limitation one or more steps of one or more methods describedor illustrated herein. As an example and not by way of limitation, oneor more computer systems 900 may perform in real time or in batch modeone or more steps of one or more methods described or illustratedherein. One or more computer systems 900 may perform at different timesor at different locations one or more steps of one or more methodsdescribed or illustrated herein, where appropriate.

In particular embodiments, computer system 900 includes a processor 902,memory 904, storage 906, an input/output (I/O) interface 908, acommunication interface 910, and a bus 912. Although this disclosuredescribes and illustrates a particular computer system having aparticular number of particular components in a particular arrangement,this disclosure contemplates any suitable computer system having anysuitable number of any suitable components in any suitable arrangement.

In particular embodiments, processor 902 includes hardware for executinginstructions, such as those making up a computer program. As an exampleand not by way of limitation, to execute instructions, processor 902 mayretrieve (or fetch) the instructions from an internal register, aninternal cache, memory 904, or storage 906; decode and execute them; andthen write one or more results to an internal register, an internalcache, memory 904, or storage 906. In particular embodiments, processor902 may include one or more internal caches for data, instructions, oraddresses. This disclosure contemplates processor 902 including anysuitable number of any suitable internal caches, where appropriate. Asan example and not by way of limitation, processor 902 may include oneor more instruction caches, one or more data caches, and one or moretranslation lookaside buffers (TLBs). Instructions in the instructioncaches may be copies of instructions in memory 904 or storage 906, andthe instruction caches may speed up retrieval of those instructions byprocessor 902. Data in the data caches may be copies of data in memory904 or storage 906 for instructions executing at processor 902 tooperate on; the results of previous instructions executed at processor902 for access by subsequent instructions executing at processor 902 orfor writing to memory 904 or storage 906; or other suitable data. Thedata caches may speed up read or write operations by processor 902. TheTLBs may speed up virtual-address translation for processor 902. Inparticular embodiments, processor 902 may include one or more internalregisters for data, instructions, or addresses. This disclosurecontemplates processor 902 including any suitable number of any suitableinternal registers, where appropriate. Where appropriate, processor 902may include one or more arithmetic logic units (ALUs); be a multi-coreprocessor; or include one or more processors 902. Although thisdisclosure describes and illustrates a particular processor, thisdisclosure contemplates any suitable processor.

In particular embodiments, memory 904 includes main memory for storinginstructions for processor 902 to execute or data for processor 902 tooperate on. As an example and not by way of limitation, computer system900 may load instructions from storage 906 or another source (such as,for example, another computer system 900) to memory 904. Processor 902may then load the instructions from memory 904 to an internal registeror internal cache. To execute the instructions, processor 902 mayretrieve the instructions from the internal register or internal cacheand decode them. During or after execution of the instructions,processor 902 may write one or more results (which may be intermediateor final results) to the internal register or internal cache. Processor902 may then write one or more of those results to memory 904. Inparticular embodiments, processor 902 executes only instructions in oneor more internal registers or internal caches or in memory 904 (asopposed to storage 906 or elsewhere) and operates only on data in one ormore internal registers or internal caches or in memory 904 (as opposedto storage 906 or elsewhere). One or more memory buses (which may eachinclude an address bus and a data bus) may couple processor 902 tomemory 904. Bus 912 may include one or more memory buses, as describedbelow. In particular embodiments, one or more memory management units(MMUs) reside between processor 902 and memory 904 and facilitateaccesses to memory 904 requested by processor 902. In particularembodiments, memory 904 includes random access memory (RAM). This RAMmay be volatile memory, where appropriate Where appropriate, this RAMmay be dynamic RAM (DRAM) or static RAM (SRAM). Moreover, whereappropriate, this RAM may be single-ported or multi-ported RAM. Thisdisclosure contemplates any suitable RAM. Memory 904 may include one ormore memories 904, where appropriate. Although this disclosure describesand illustrates particular memory, this disclosure contemplates anysuitable memory.

In particular embodiments, storage 906 includes mass storage for data orinstructions. As an example and not by way of limitation, storage 906may include a hard disk drive (HDD), a floppy disk drive, flash memory,an optical disc, a magneto-optical disc, magnetic tape, or a UniversalSerial Bus (USB) drive or a combination of two or more of these. Storage906 may include removable or non-removable (or fixed) media, whereappropriate. Storage 906 may be internal or external to computer system900, where appropriate. In particular embodiments, storage 906 isnon-volatile, solid-state memory. In particular embodiments, storage 906includes read-only memory (ROM). Where appropriate, this ROM may bemask-programmed ROM, programmable ROM (PROM), erasable PROM (EPROM),electrically erasable PROM (EEPROM), electrically alterable ROM (EAROM),or flash memory or a combination of two or more of these. Thisdisclosure contemplates mass storage 906 taking any suitable physicalform. Storage 906 may include one or more storage control unitsfacilitating communication between processor 902 and storage 906, whereappropriate. Where appropriate, storage 906 may include one or morestorages 906. Although this disclosure describes and illustratesparticular storage, this disclosure contemplates any suitable storage.

In particular embodiments, I/O interface 908 includes hardware,software, or both, providing one or more interfaces for communicationbetween computer system 900 and one or more I/O devices. Computer system900 may include one or more of these I/O devices, where appropriate. Oneor more of these I/O devices may enable communication between a personand computer system 900. As an example and not by way of limitation, anI/O device may include a keyboard, keypad, microphone, monitor, mouse,printer, scanner, speaker, still camera, stylus, tablet, touch screen,trackball, video camera, another suitable I/O device or a combination oftwo or more of these. An I/O device may include one or more sensors.This disclosure contemplates any suitable I/O devices and any suitableI/O interfaces 908 for them. Where appropriate, I/O interface 908 mayinclude one or more device or software drivers enabling processor 902 todrive one or more of these I/O devices. I/O interface 908 may includeone or more I/O interfaces 908, where appropriate. Although thisdisclosure describes and illustrates a particular I/O interface, thisdisclosure contemplates any suitable I/O interface.

In particular embodiments, communication interface 910 includeshardware, software, or both providing one or more interfaces forcommunication (such as, for example, packet-based communication) betweencomputer system 900 and one or more other computer systems 900 or one ormore networks. As an example and not by way of limitation, communicationinterface 910 may include a network interface controller (NIC) ornetwork adapter for communicating with an Ethernet or other wire-basednetwork or a wireless NIC (WNIC) or wireless adapter for communicatingwith a wireless network, such as a WI-FI network. This disclosurecontemplates any suitable network and any suitable communicationinterface 910 for it. As an example and not by way of limitation,computer system 900 may communicate with an ad hoc network, a personalarea network (PAN), a local area network (LAN), a wide area network(WAN), a metropolitan area network (MAN), or one or more portions of theInternet or a combination of two or more of these. One or more portionsof one or more of these networks may be wired or wireless. As anexample, computer system 900 may communicate with a wireless PAN (WPAN)(such as, for example, a BLUETOOTH WPAN), a WI-FI network, a WI-MAXnetwork, a cellular telephone network (such as, for example, a GlobalSystem for Mobile Communications (GSM) network), or other suitablewireless network or a combination of two or more of these. Computersystem 900 may include any suitable communication interface 910 for anyof these networks, where appropriate. Communication interface 910 mayinclude one or more communication interfaces 910, where appropriate.Although this disclosure describes and illustrates a particularcommunication interface, this disclosure contemplates any suitablecommunication interface.

In particular embodiments, bus 912 includes hardware, software, or bothcoupling components of computer system 900 to each other. As an exampleand not by way of limitation, bus 912 may include an AcceleratedGraphics Port (AGP) or other graphics bus, an Enhanced Industry StandardArchitecture (EISA) bus, a front-side bus (FSB), a HYPERTRANSPORT (HT)interconnect, an Industry Standard Architecture (ISA) bus, an INFINIBANDinterconnect, a low-pin-count (LPC) bus, a memory bus, a Micro ChannelArchitecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, aPCI-Express (PCIe) bus, a serial advanced technology attachment (SATA)bus, a Video Electronics Standards Association local (VLB) bus, oranother suitable bus or a combination of two or more of these. Bus 912may include one or more buses 912, where appropriate. Although thisdisclosure describes and illustrates a particular bus, this disclosurecontemplates any suitable bus or interconnect.

Herein, a computer-readable non-transitory storage medium or media mayinclude one or more semiconductor-based or other integrated circuits(ICs) (such, as for example, field-programmable gate arrays (FPGAs) orapplication-specific ICs (ASICs)), hard disk drives (HDDs), hybrid harddrives (HHDs), optical discs, optical disc drives (ODDs),magneto-optical discs, magneto-optical drives, floppy diskettes, floppydisk drives (FDDs), magnetic tapes, solid-state drives (SSDs),RAM-drives, SECURE DIGITAL cards or drives, any other suitablecomputer-readable non-transitory storage media, or any suitablecombination of two or more of these, where appropriate. Acomputer-readable non-transitory storage medium may be volatile,non-volatile, or a combination of volatile and non-volatile, whereappropriate.

Miscellaneous

Herein, “or” is inclusive and not exclusive, unless expressly indicatedotherwise or indicated otherwise by context. Therefore, herein, “A or B”means “A, B, or both,” unless expressly indicated otherwise or indicatedotherwise by context. Moreover, “and” is both joint and several, unlessexpressly indicated otherwise or indicated otherwise by context.Therefore, herein, “A and B” means “A and B, jointly or severally,”unless expressly indicated otherwise or indicated otherwise by context.

The scope of this disclosure encompasses all changes, substitutions,variations, alterations, and modifications to the example embodimentsdescribed or illustrated herein that a person having ordinary skill inthe art would comprehend. The scope of this disclosure is not limited tothe example embodiments described or illustrated herein. Moreover,although this disclosure describes and illustrates respectiveembodiments herein as including particular components, elements,functions, operations, or steps, any of these embodiments may includeany combination or permutation of any of the components, elements,functions, operations, or steps described or illustrated anywhere hereinthat a person having ordinary skill in the art would comprehend.Furthermore, reference in the appended claims to an apparatus or systemor a component of an apparatus or system being adapted to, arranged to,capable of, configured to, enabled to, operable to, or operative toperform a particular function encompasses that apparatus, system,component, whether or not it or that particular function is activated,turned on, or unlocked, as long as that apparatus, system, or componentis so adapted, arranged, capable, configured, enabled, operable, oroperative.

What is claimed is:
 1. A method comprising: accessing a social graphcomprising a plurality of nodes and a plurality of edges connecting thenodes, each of the edges between two of the nodes representing a singledegree of separation between them, the nodes comprising: a first nodecorresponding to a first user associated with an online social network;and a plurality of second nodes that each correspond to a concept or asecond user associated with the online social network; receiving fromthe first user a structured query comprising references to one or moreselected nodes from the plurality of nodes and one or more selectededges from the plurality of edges; generating a query command based onthe structured query, wherein the query command comprises an inner queryconstraint and an outer query constraint; identifying a first set ofnodes matching the inner query constraint and at least in part matchingthe outer query constraint; identifying a second set of nodes matchingthe outer query constraint; and generating one or more search resultsbased on the first and second sets of nodes, wherein each search resultcorresponds to a node of the plurality of nodes.
 2. The method of claim1, wherein the inner query constraint is for a first object-type and theouter query constraint is for a second object-type.
 3. The method ofclaim 2, wherein the first object-type and the second object-type areeach selected from a group consisting of: a user, a photo, a post, awebpage, an application, a location, or a user group.
 4. The method ofclaim 1, further comprising: scoring the first set of nodes; and scoringthe second set of nodes based at least in part on the scores of thefirst set of nodes.
 5. The method of claim 1, wherein: the inner queryconstraint is for one or more nodes of the plurality of nodes connectedto a first of the selected nodes by a first of the selected edges; andthe outer query constraint is for one or more nodes of the plurality ofnodes connected to a second of the selected nodes by a second of theselected edges.
 6. The method of claim 1, wherein identifying the firstset of nodes matching the inner query constraint and at least in partmatching the outer query constraint comprises: identifying a firstnumber of nodes matching at least the inner query constraint; andidentifying a second number of nodes matching both the inner queryconstraint and the outer query constraint.
 7. The method of claim 6,wherein the first number is a first percentage and the second number isa second percentage.
 8. The method of claim 1, wherein identifying thefirst set of nodes matching the inner query constraint and at least inpart matching the outer query constraint comprises: identifying a firstnumber of nodes matching either the inner query constraint or the outerquery constraint; and identifying a second number of nodes matching boththe inner query constraint and the outer query constraint.
 9. The methodof claim 1, further comprising scoring the search results.
 10. Themethod of claim 1, further comprising determining one or more searchintents based on one or more of the selected nodes or one or more of theselected edges referenced in the structured query.
 11. The method ofclaim 10, further comprising scoring the search results based on one ormore of the search intents.
 12. The method of claim 11, wherein the oneor more search intents comprise an intent to exclude converse searchresults, and wherein scoring the search results comprises downgradingthe score of each search result corresponding to at least one of theselected nodes referenced in the structured query.
 13. The method ofclaim 11, wherein the one or more search intents comprise an intent toexclude inner search results, and wherein scoring the search resultscomprises downgrading the score of each search result corresponding toat least one of the nodes of the first set of nodes.
 14. The method ofclaim 11, wherein the one or more search intents comprise an intent toexclude duplicate search results, and wherein scoring the search resultscomprises downgrading the score of each search result corresponding to anode that matches both the inner query constraint and the outer queryconstraint.
 15. The method of claim 10, wherein generating the querycommand is further based on the one or more search intents.
 16. Themethod of claim 10, wherein one or more of the inner query constraint orthe outer query constraint is based on one or more of the searchintents.
 17. The method of claim 1, wherein the one or more searchresults comprise to one or more nodes of the second set of nodesmatching the outer query constraint, each search result corresponding toa second node that is related by a constraint of the query command to atleast one node of the first set of nodes matching the inner queryconstraint.
 18. The method of claim 1, wherein the inner queryconstraint is nested in the outer query constraint.
 19. One or morecomputer-readable non-transitory storage media embodying software thatis operable when executed to: access a social graph comprising aplurality of nodes and a plurality of edges connecting the nodes, eachof the edges between two of the nodes representing a single degree ofseparation between them, the nodes comprising: a first nodecorresponding to a first user associated with an online social network;and a plurality of second nodes that each correspond to a concept or asecond user associated with the online social network; receive from thefirst user a structured query comprising references to one or moreselected nodes from the plurality of nodes and one or more selectededges from the plurality of edges; generate a query command based on thestructured query, wherein the query command comprises an inner queryconstraint and an outer query constraint; identify a first set of nodesmatching the inner query constraint and at least in part matching theouter query constraint; identify a second set of nodes matching theouter query constraint; and generate one or more search results based onthe first and second sets of nodes, wherein each search resultcorresponds to a node of the plurality of nodes.
 20. A systemcomprising: one or more processors; and a memory coupled to theprocessors comprising instructions executable by the processors, theprocessors operable when executing the instructions to: access a socialgraph comprising a plurality of nodes and a plurality of edgesconnecting the nodes, each of the edges between two of the nodesrepresenting a single degree of separation between them, the nodescomprising: a first node corresponding to a first user associated withan online social network; and a plurality of second nodes that eachcorrespond to a concept or a second user associated with the onlinesocial network; receive from the first user a structured querycomprising references to one or more selected nodes from the pluralityof nodes and one or more selected edges from the plurality of edges;generate a query command based on the structured query, wherein thequery command comprises an inner query constraint and an outer queryconstraint; identify a first set of nodes matching the inner queryconstraint and at least in part matching the outer query constraint;identify a second set of nodes matching the outer query constraint; andgenerate one or more search results based on the first and second setsof nodes, wherein each search result corresponds to a node of theplurality of nodes.